Thanks for your help -- I searched around some more and I think I
have the basic idea down -- if you want to implement a COM interface, it should
look something like this:

Use makepy -i to generate a file from the typelib containing the
interface definition.
In my case the file generated is named:
13F76618-D199-4485-8C95-DC524958686Cx0x2x0.py

I assume the typelib GUID is: 13F76618-D199-4485-8C95-DC524958686C
and the typelib version is: 2,0

The interface I'm trying to implement is named: "IMbtQuotesNotify"

universal.RegisterInterfaces('{13F76618-D199-4485-8C95-DC524958686C}',0,2,0,["IMbtQuotesNotify"])
class Q:
    _com_interfaces_ = ['IMbtQuotesNotify']
    _typelib_guid_ = '{13F76618-D199-4485-8C95-DC524958686C}'
    _typelib_version_ = 2, 0

    def OnQuoteData(self,pQuote):
        print "got onquote!"
        print type(pQuote)
        print "%s" % pQuote

import win32com.server.util
qnotify = win32com.server.util.wrap(Q())

The object named qnotify is now something I can pass to another COM
function that
expects an object implementing the interface.

import win32com.client as com
quote = com.Dispatch("MBTrading.MbtQuotes")
quote.AdviseSymbol(qnotify,'GOOG',1)

The callback functions defined in qnotify should be called with quote
data whenever a new quote for 'GOOG' is available.  For whatever
reason, this doesn't happen. Sometimes the OnQuoteData callback is
invoked with an int (the int is 1240772, if that means anything)
instead of the quote datatype as advertised. Sometimes the interpreter
crashes.  However, I suspect that the above code is correct, unless I
am still doing something wrong.  (Perhaps using wrap is not the right
function for creating an object that is passed as an argument to
another COM function?)

Thanks again for your help!



> > 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!
>
> You should be able to implement it just as you would a small COM server.
> Basically, your class would need to specify the interface with
>  _com_interfaces_=[iid of Foo]
> and define an event method.
> def OnSomeEvent(self,.....):
>
>          Roger

Thanks for your help -- I've created a class as you've suggested.
The function that takes as an argu
_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to