[python-win32] Trying to implement an third-party interface in COM for events

Mark Hammond skippy.hammond at gmail.com
Mon Apr 13 09:09:55 CEST 2009


On 11/04/2009 4:26 AM, Kapil fadnis wrote:
> I think this has been talked about on a previous thread but its an old
> thread here but I am hoping to get some feedback that will help me
> understand the issue,
>
> http://mail.python.org/pipermail/python-win32/2006-September/005044.html
>
>
> I have an interface
> MBTQUOTELib.
> IMbtQuotesNotify
> which has four methods to be implemented, each of which is an event on
> the server side i.e. my broker.
> One of the methods is "OnQuoteData(QUOTERECORD). The way I have seen it
> being implemented (in the thread above) is
> run makepy - i on the interface definition, i use PythonWin for this
> which gives me a .py file.
> 13F76618-D199-4485-8C95-DC524958686Cx0x2x0.py
>
> The implementation is
> -------------------------------------------------------------------------------------------
> from win32com import universal
> 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(),useDispatcher=1)
>
> import win32com.client as com
> mbtCom = com.Dispatch("MBTrading.MbtComMgr")
> mbtCom.DoLogin(9,"myusername","mypassword","")
> quote = mbtCom.Quotes
> quote.AdviseSymbol(qnotify,'AAPL',1)

See if adding a call to pythoncom.PumpMessages() at the very end makes a 
difference...

Cheers,

Mark


More information about the python-win32 mailing list