[python-win32] Implementing custom com interface, passing it to another com object for callbacks

Thomas Heller theller at ctypes.org
Fri Dec 8 10:19:14 CET 2006


johnny loops schrieb:
> Thomas, thanks for your help.  Everything seemed to work except when I
> needed to pass my com object to another com function to receive
> callbacks
> 
>> > o=myComObjClass()
>> > otherDispatchedComObject.FunctionThatNeedsInterface(o, otherInputs)
> 
> The other dispatched com object was created using win32com, and other
> functions of it work fine.  However, this specific function needs to
> be called with a com object implementing the interface as one of the
> inputs, and then its functions will be called as callbacks. The error
> I get when I pass o to this function is
> 
> ValueError: argument is not a COM object
> 
> Do you have any suggestions?  Thanks again for your help

If I understand you correctly, you have created the otherDispatchedComObject
by calling some win32com functions, and you want to pass a comtypes object
to a method of otherDispatchedComObject?

If this is so, then it fails because win32com does not know anything about
comtypes.  Fortunately, pythoncom25.dll exposes a function that can be called
with ctypes to do the conversion.  I have attached a module containing a unittest
that does this.  The 'comtypes2pywin' function accepts a comtypes COM pointer
or a comtypes COMObject instance and returns a win32com object - a <PyIDispatch>
object, or a <PyOIUnknown> object.

I think that should do what you want - please report back.  This code should probably
go into comtypes somewhere.

Thomas
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test_win32com_interop.py
Url: http://mail.python.org/pipermail/python-win32/attachments/20061208/ba2a68b3/attachment.asc 


More information about the Python-win32 mailing list