Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34629

Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

Newsgroups comp.lang.python
Date 2012-12-11 07:48 -0800
References <38a14001-82b6-4a91-b3ad-2cb5c8ee580d@googlegroups.com> <mailman.682.1355173145.29569.python-list@python.org> <ed7dd76c-c1f2-4d33-9e14-41e8be65c29a@googlegroups.com> <mailman.704.1355188608.29569.python-list@python.org>
Subject Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"
From bitbucket <coder1024@gmail.com>
Message-ID <mailman.733.1355240942.29569.python-list@python.org> (permalink)

Show all headers | View raw


On Monday, December 10, 2012 8:16:43 PM UTC-5, Mark Hammond wrote:
> "out" params are best supported if the object supplied a typelib - then 
> Python knows the params are out and does the right thing automagically. 
>   If out params are detected, the result of the function will be a tuple 
> of (real_result, out_param1, ...)
> 
> Even if no typelib is supported, you can access them with a little pain 
> via the win32com.client.Dispatch() object.  You might like to follow up 
> to the python-win32@python.org mailing list where many people will be 
> able to help.
> 
> HTH,
> 
> Mark

Mark, thanks for the reply.  In this case, I have a type library and attempted to use MakePy but it doesn't seem to be working as expected.

I was reading through CH12 of your Python Programming on Win32 book (http://oreilly.com/catalog/pythonwin32/chapter/ch12.html).  I was hopeful given your description of MakePy that I could get this to work.  It appears that you're saying MakePy will convert "byref" args in a function over to return values.

For example, the IDL in the server includes the following 3 functions.

			[id(1)] void ShowMessage(BSTR msg);
			[id(2)] void GetSettingValue(BSTR settingName, BSTR* settingValue);
			[id(3)] void SetSettingValue(BSTR settingName, BSTR settingValue);

The thorny one is the GetSettingValue since it takes the out param.  When I run MakePy, it generates the below.

	def ShowMessage(self, msg=defaultNamedNotOptArg):
		return self._oleobj_.InvokeTypes(1, LCID, 1, (24, 0), ((8, 0),),msg
			)

	def GetSettingValue(self, settingName=defaultNamedNotOptArg, settingValue=defaultNamedNotOptArg):
		return self._oleobj_.InvokeTypes(2, LCID, 1, (24, 0), ((8, 0), (16392, 0)),settingName
			, settingValue)

	def SetSettingValue(self, settingName=defaultNamedNotOptArg, settingValue=defaultNamedNotOptArg):
		return self._oleobj_.InvokeTypes(3, LCID, 1, (24, 0), ((8, 0), (8, 0)),settingName
			, settingValue)

I noticed that the argument type is different for the out param (16392 instead of 8).  However, it doesn't appear to me that its generating return values instead of args (though I'm not very experienced in python).

I tried invoking these in python.  The ShowMessage and SetSettingValue work great.  I can't get the GetSettingValue to work though.  Perhaps there's a different syntax I need when using the MakePy generated code?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" bitbucket <coder1024@gmail.com> - 2012-12-10 11:13 -0800
  Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" Terry Reedy <tjreedy@udel.edu> - 2012-12-10 15:58 -0500
    Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" bitbucket <coder1024@gmail.com> - 2012-12-10 13:39 -0800
      Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-12-10 18:39 -0500
      Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" Mark Hammond <skippy.hammond@gmail.com> - 2012-12-11 12:16 +1100
        Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" bitbucket <coder1024@gmail.com> - 2012-12-11 07:48 -0800
          Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" bitbucket <coder1024@gmail.com> - 2012-12-11 07:54 -0800
          Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" bitbucket <coder1024@gmail.com> - 2012-12-11 07:54 -0800
          Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" Mark Hammond <mhammond@skippinet.com.au> - 2012-12-12 08:55 +1100
        Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" bitbucket <coder1024@gmail.com> - 2012-12-11 07:48 -0800
    Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" bitbucket <coder1024@gmail.com> - 2012-12-10 13:39 -0800
  Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" Paul Kölle <paul@subsignal.org> - 2012-12-11 09:42 +0100
    Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" bitbucket <coder1024@gmail.com> - 2012-12-11 07:37 -0800
    Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params" bitbucket <coder1024@gmail.com> - 2012-12-11 07:37 -0800

csiph-web