[python-win32] How to implement a COM interface (that is not part of a COM class)

Ken Channing kenchanningphd at gmail.com
Wed Sep 13 23:10:20 CEST 2006


Hi -- the COM object I'm working on has a number of methods I am able
to use fairly well by following the various win32com examples around.

However, one of the methods' arguments takes a callback that
"implements an interface" (I'm new to win COM terminology but I think
this phrase has a specific context when applied here -- my guess is an
'interface' is similar to a 'template' in C++?).

I searched for examples of implementing callbacks such as this one:

class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
   """Called when a word/phrase is successfully recognized  -
       ie it is found in a currently open grammar with a sufficiently high
       confidence"""
   def OnRecognition(self, StreamNumber, StreamPosition,
RecognitionType, Result):
       newResult = win32com.client.Dispatch(Result)
       print "You said: ",newResult.PhraseInfo.GetText()

However, in my case, the interface is not associated with any class
that I can find,
so I can't use DispatchWithEvents or getevents to get an object to
subclass from.  (When I try to use getevents on the clsid of the
interface from the makepy generated file, it returns None)

I think the post here outlines a similar problem:
http://mail.python.org/pipermail/python-win32/2004-May/001990.html

Is there some obvious way to do this that I'm missing?
In the VB version of the program I'm trying to re-implement in python,
it seems to be able to
implement the interface by simply calling "Implements Foo" and subclassing by
"Private Sub Foo_OnSomeEvent(..."

Thanks for any help!


More information about the Python-win32 mailing list