Using Python with COM to communicate with proprietary Windows software

Thomas Heller theller at python.net
Tue Sep 13 10:15:18 CEST 2005


Joakim Persson <zaladin at home.se> writes:

> 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?

There is not yet any server support in comtypes, but it will be added.
In the meantime you could use the ctypes.com package that is included in
ctypes itself, there are even samples.

Thomas



More information about the Python-list mailing list