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

johnny loops johnnyloops at gmail.com
Wed Dec 6 19:17:39 CET 2006


I have been pining over implementing what seems to be a VB custom com
interface for some time now, so I thought I would post to the list to see if
anyone could help.

I have a com component on which I have run makepy.  The function generates a
couple of classes with functions and callbacks that all work fine when I
DispatchWithEvents.  However there is one interface that I cannot figure out
how to use.  This interface is only referenced in the vtables section as

foo_vtables_dispatch_ = 0
foo_vtables_ = [
    (( 'OnFunc1' , 'variable1' , ), 1610678272, (1610678272, (), [ (36, 1,
None, None) , ], 1 , 1 , 4 , 0 , 12 , (3, 0, None, None) , 0 , )),
    (( 'OnFunc2' , 'variable2' , ), 1610678273, (1610678273, (), [ (36, 1,
None, None) , ], 1 , 1 , 4 , 0 , 16 , (3, 0, None, None) , 0 , )),
]

foo is also listed in the VTablesToClassMap  and the NamesToIIDMap

Now, OnFunc1 and OnFunc2 are callback functions of an interface that I need
to implement.  Once I implement the interface, I need to pass that object to
another com object that will fire callbacks.  So reading some of these
lists, I thought I should register the interface, create a server, wrap the
server and pass it to the other com function.

For example:
universal.RegisterInterfaces(CLSID,0,2,0,["foo"])
class F:
      _com_interfaces_=["foo"]
     _typelib_guid_ = CLSID
     _typelib_version_ = 2,0
    _public_methods_ = [] or ['OnFunc1', 'OnFunc2'] -- i've tried both
      def OnFunc1:
            do some stuff
      def OnFunc2
            do some other stuff
o=wrap(F)
otherDispatchedComObject.FunctionThatNeedsInterface(o, otherInputs)

This does not produce any errors, but callbacks to OnFunc1 and OnFunc2 never
fire-- and I know they are firing.  Also wrapping with a debugging
dispatcher adds produces no information.  Callbacks to the regularly
dispatched com objects do fire.

So my question is: Is what I am trying to do possible using win32com?  Does
this seem like it should work?  If not, does anyone have any suggestions
using comtypes? I have read that vtable interfaces should be no problem for
comtypes, but I can't find much in the way of documentation/examples.
Basically, I'm lost here, to the point where I may have to switch to VB
(eek)--so any help would be appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20061206/ff03d880/attachment.htm 


More information about the Python-win32 mailing list