[python-win32] Calling an OLE Automation (IDispatch) server which uses "out params"
Dave Calkins
dave at kinematics.com
Tue Dec 18 02:33:29 CET 2012
On 12/17/2012 8:25 PM, Mark Hammond wrote:
> Dave sent me the source via email.
>
> The root problem is that the MFC project is not supporting the
> GetTypeInfo() and associated calls, and TBH I'm not sure how hard it
> would be to make it support that. The end result is that the makepy
> support for the object isn't being used as pywin32 can't associate the
> object with the typelib, and thus isn't specifying that additional
> second param. This is also the reason you can't automagically
> generate the typelib using, eg,
> win32com.client.gencache.EnsureDispatch() - you are forced to run
> makepy manually and specify the exact typelib.
>
> There is actually a deficiency in pywin32 here too - it *does* know
> that MyApp.Application has a generated class, but it never tries that
> route - instead it creates the object and tries to use the typeinfo
> stuff to make the association. I think a bug on sourceforge for this
> would be good.
>
> So after running makepy, a work-around is:
>
> >>> klass=win32com.client.gencache.GetClassForProgID("MyApp.Application")
> >>> x = klass()
> >>> x.GetSettingValue("foo")
> u'foo=testValue123'
> >>>
>
> If you can work out how to get the MFC app to respond to the
> GetTypeInfo() and associated calls, it would all "just work". ie:
>
> >>> x=win32com.client.Dispatch("MyApp.Application")._oleobj_
> >>> x
> <PyIDispatch at 0x00000000023590B0 with obj at 0x00000000003C0298>
> >>> x.GetTypeInfo()
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> pywintypes.com_error: (-2147352565, 'Invalid index.', None, None)
> >>>
>
> should work - eg, a similar example using a WMI object:
>
> >>> x = win32com.client.Dispatch("WbemScripting.SWbemLocator")._oleobj_
> >>> x
> <PyIDispatch at 0x0000000002359110 with obj at 0x0000000002C513D0>
> >>> x.GetTypeInfo()
> <PyITypeInfo at 0x00000000023590B0 with obj at 0x00000000003EB8B8>
> >>>
>
> So it kinda sucks :(
>
> Mark
>
Thanks for all the help Mark! I'll look into what it would take to
support the GetTypeInfo() call on the MFC side. It sounds like the
work-around will do just fine even if I can't get the GetTypeInfo()
thing going.
Dave
More information about the python-win32
mailing list