[python-win32] Implementing custom com interface, passing it to another com object for callbacks
Thomas Heller
theller at ctypes.org
Thu Dec 7 15:09:29 CET 2006
johnny loops schrieb:
> Thanks, these references are really helpful, and I think I understand
> a lot more of the path using comtypes. Continuing with my pseudo code
> example-- this is what I think I should do:
>
> -run GetModule() on the library, which should create the interface foo
Yes.
> -Create a class implementing foo
Yes.
> -Create object implementing interface foo
Yes.
> -Pass the object to the other com function that will fire callbacks to it
>
> comtypes.client.GetModule('CLSID that contains foo')
> class myComObjClass(COMObject):
> _com_interfaces_ = [foo]
>
> def foo_OnFunc1(self, this, variable1):
> do some stuff on callback
> def foo_OnFunc2(self, this, variable2):
> do some other stuff
>
> o=myComObjClass()
> otherDispatchedComObject.FunctionThatNeedsInterface(o, otherInputs)
>
> What I'm not sure about is the step that creates the object. Before,
> when I tried using win32com, I thought I had to wrap a server to pass
> it-- this didn't work, so I could have been off the mark here. Does
> this look right? Is it really this easy?
Yes, it should work this way. The COMObject base class takes care of the rest.
Thomas
More information about the Python-win32
mailing list