Using Python with COM to communicate with proprietary Windows software

Joakim Persson zaladin at home.se
Sat Sep 10 20:43:38 CEST 2005


On Fri, 09 Sep 2005 08:36:00 +0200, Thomas Heller <theller at python.net>
wrote:

>Sounds like a perfect job for comtypes, which is a COM library
>implemented in pure Python, based on ctypes.  comtypes should make it
>easy to access custom (non-dispatch derived) com interfaces, or the
>vtable based part of dual interfaces - it would be good however, if you
>have a type library for the interfaces.
>
>http://sourceforge.net/projects/comtypes/
>
>No docs yet, but there are tests included which should get you started.
>
>(I have released and announced this 3 weeks ago, but haven't got a
>single feedback.  So it seems the need to access custom interfaces is
>very low.)
>
>Thommas

After some testing today, it does seem to do exactly what I wanted --
I can now access the "custom" but IDispatch-like COM interface that I
couldn't access with win32com (or with Java + jawin). It might be
possible in other ways, but using comtypes was definitely the most
painfree way (everything, including the return values from the
methods, worked as expected). Thank you very much. 

Of course, this does not complete my task -- although I can now use my
interface to send messages and commands to the big log tool, I still
need to implement a COM server and pass a pointer to its interface
through one of the messages to the com server to be able to receive
data: 

BridgeInterface.StartLogging(filename)   <--- works fine, didn't work
before
BridgeInterface.Advise(ptr)  <--- Now, I need to create a new
interface for receiving the data sent from the log application, so
that I can (at first) print it

This _shouldn't_ be too difficult -- I know which methods must be
implemented (basically just some kind of event handling to deal with
randomly arriving log points, should be implemented as "onMsg()" on my
COM server side, and some other similar methods), but I don't really
know how. I have tried doing simple COM servers using win32com, but is
it equally possible to implement such a simple thing in comtypes? I
didn't find any server side examples in comtypes, but perhaps there is
a way?

-- 
Joakim Persson
M.Sc student, CS/E @ LTH



More information about the Python-list mailing list