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

johnny loops johnnyloops at gmail.com
Sun Dec 10 00:08:43 CET 2006


Thomas,

That did it! Thank you very much for your help.   Calling the
comtypes2pywin function on the object worked.  After that, I created
the com object 'otherDispatchedComObject' using comtypes and that also
worked.  Again, thanks for your help!


On 12/8/06, Thomas Heller <theller at ctypes.org> wrote:
> 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


More information about the Python-win32 mailing list