Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > accessing an OLE Automation (IDispatch) server from python whichrequires the use of "out params"

Reply
Thread Tools

accessing an OLE Automation (IDispatch) server from python whichrequires the use of "out params"

 
 
bitbucket
Guest
Posts: n/a
 
      12-11-2012
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- 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/pythonwin...pter/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 Irun 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 . 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 workgreat. I can't get the GetSettingValue to work though. Perhaps there's adifferent syntax I need when using the MakePy generated code?
 
Reply With Quote
 
 
 
 
bitbucket
Guest
Posts: n/a
 
      12-11-2012
On Tuesday, December 11, 2012 10:48:53 AM UTC-5, bitbucket wrote:
>
> I noticed that the argument type is different for the out param (16392 instead of . However, it doesn't appear to me that its generating return values instead of args (though I'm not very experienced in python).
>


I see that the value 16392 is really VT_BYREF | VT_BSTR and 8 is just VT_BSTR. So in that case it appears MakePy is taking noticed at least of the VT_BYREF and including that in the generated code (since it uses 16392).

So maybe there's a special way I need to call the generated wrapper?
 
Reply With Quote
 
 
 
 
bitbucket
Guest
Posts: n/a
 
      12-11-2012
On Tuesday, December 11, 2012 10:48:53 AM UTC-5, bitbucket wrote:
>
> I noticed that the argument type is different for the out param (16392 instead of . However, it doesn't appear to me that its generating return values instead of args (though I'm not very experienced in python).
>


I see that the value 16392 is really VT_BYREF | VT_BSTR and 8 is just VT_BSTR. So in that case it appears MakePy is taking noticed at least of the VT_BYREF and including that in the generated code (since it uses 16392).

So maybe there's a special way I need to call the generated wrapper?
 
Reply With Quote
 
Mark Hammond
Guest
Posts: n/a
 
      12-11-2012
On 12/12/2012 2:48 AM, bitbucket wrote:
> 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- 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/pythonwin...pter/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 . 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?


Seeing the "real" return value is void, it should just be a matter of:

settingValue = ob.GetSettingValue("settingName")

Mark
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Uploading files to an an FTP site through a proxy server whichrequires authentication tkpmep@hotmail.com Python 0 02-09-2011 06:22 PM
CAPICOM - Windows Server 2003 R2 64 bit - OLE automation error =?Utf-8?B?bGVyeHN0?= Windows 64bit 0 02-07-2007 04:22 PM
Ole ole Patrick.O.Ige ASP .Net 0 07-16-2006 08:10 AM
Creating an OLE server document in Python (MFC/OLE/COM/Python newbie) Drew Pihera Python 0 02-04-2004 07:48 PM
Win32::OLE adding shape to OLE Object (xlsheet) in PPT Lance Hoffmeyer Perl Misc 0 11-17-2003 07:44 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57