[python-win32] win32com.client: Struggling with dynamic dispatch, behavior differs when debugging

Dominik . dominik.heller1 at gmail.com
Tue Sep 27 12:33:18 EDT 2016


Hi,

I’m trying to control an existing COM server (C++ code) with a python COM
client.

Unfortunately, no type library exists for most of the COM objects. Thus I’m
restricted to the dynamic dispatch implementation.



This is my sample code. Its equivalent works flawlessly when called via
VBA, moreover I'm sure that the requested COM methods exist in the server.



import win32com.client

obj_1 = win32com.client.DispatchEx(“MyCOMServerApplication”)

obj_2 = obj_1.NewDocument() # works, returns a new dynamic dispatch
(<CDispatch: None>)

obj_2.SubObject.DoSomething(“MyArgument”) # works, but only if I don’t step
into it (i.e. into CDispatch.__getattr__)

#obj_2.GetSomeNumber()  # TypeError: 'int' object is not callable

obj_2.GetSomeNumber  # works correctly, but only if I don’t step into it
(i.e. into CDispatch.__getattr__)

obj_2.DoSomething(“MyArgument”) # doesn’t work



I also tried passing any arguments (e.g. “MyArgument”) as VARIANTs, but to
no avail.


Evidently I’m very confused, especially since the behavior differs when
stepping into the relevant python code.

I have also read that the dynamic dispatch implementation doesn't support
by-ref parameters, is this information still up to date?

Looking forward to any help. If needed, I'll gladly provide more
information.


Thanks,

Dominik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20160927/ee1b6afa/attachment.html>


More information about the python-win32 mailing list