Python COM Questions

Dave Kirby dkirby at orchestream.com
Wed May 1 05:50:59 EDT 2002


The Background:
I am trying to write a GUI test automation system using the Microsoft Active
Accessibility, which provides a COM interface for controlling the GUI
elements of another process. (see http://msdn.microsoft.com/accessibility
for details).  The problem is that this has a DLL (oleacc.dll) with factory
functions to generate COM wrappers for GUI elements, for example:

STDAPI AccessibleObjectFromWindow(
  HWND hwnd,
  DWORD dwObjectID,
  REFIID riid,
  void** ppvObject
);

this function creates a IAccessible COM object and writes its address into
*ppvObject.  The problem is that I can't figure out how to call this
function (or any of the others) from Python.

The Questions:
How do I get Python to access the factory functions?  I can see two options:

1) write a C++ Python module, perhaps using SWIG, that exposes the
functions.  If I do this how do I convert the C++ created COM object into
something that Python COM can use?  I presume that I need to generate a
Python wrapper round it, but I cant find out how to do that.

2) write a COM server that creates a COM factory object with these functions
as methods.  This would be a more generic solution since it would be usable
by any language that uses COM (and IMHO, what MS should have done in the
first place).   If I do this, I would like to be able to make the COM server
InProc, so I dont have to go through the messyness of registering it with
Windows.  So how do I call an InProc server from Python?

3) Is there any other way to call the dll?  I had a brief look at Sam
Rushing's calldll module, but there is no documentation for it and I dont
know how (or if) it would handle the creation of the COM object.

Any help would be greatly appreciated.  If I get this working then I will
push for my employer to make it open source, so that the Python community
can benefit from it.

        Dave Kirby





More information about the Python-list mailing list