Using Python with COM to communicate with proprietary Windows software

Thomas Heller theller at python.net
Fri Sep 9 02:36:00 EDT 2005


Joakim Persson <zaladin at home.se> writes:

[...]
> This means that I must come up with a way to interface Python with
> this log tool. After some investigations, I have run inte problems --
> my inital approach was to use Python + win32com to communicate with
> the COM interface. Unfortunately, it seems as if win32com, even if I
> makepy the log tool executable (which gives me the full range of
> available functions of the interface, just as expected), cannot be
> used, since the interface is not a simple IDispatch interface. Also, I
> discovered that the Python client must also implement a COM server to
> receive the log information as it is generated by the embedded device,
> passed into the log tool and then sent by the log tool COM server. 
>
> I have a rather bloated C++ client prototype which "works", so I
> should have all the code needed to invoke the interface, but this
> client is of course rather bloated in itself and not suitable for my
> experimental programming approach. Am I right in believing that the
> COM interface I am trying to use is of what is called a "custom" type,
> that I cannot access using Python + win32com?

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



More information about the Python-list mailing list