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

johnny loops johnnyloops at gmail.com
Wed Dec 6 23:06:29 CET 2006


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

-Create a class implementing foo

-Create object implementing interface foo

-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?


More information about the Python-win32 mailing list