Python COM Questions

Mark Hammond mhammond at skippinet.com.au
Wed May 1 10:23:14 EDT 2002


Dave Kirby wrote:
> 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.

There are functions exported from pythoncomxx.dll, but you will still be 
faced with the fact that Pythoncom doesn't understand the interface in 
question.

You can add support for this interface manually, also using SWIG.  See 
the source code to the win32comext\exchange tree for an example.

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

InProc servers still need to be registered.  You call an InProc object 
like any other object; by using its CLSID.

If IAccessible is described in a type library, another alternative would 
be to help getting support for arbitary interfaces into PythonCOM - but 
this is likely to be harder, as it is new ground.  We do have the "other 
side" implemented (ie, implementing interfaces) so adding support for 
calling them should be just as doable.

Mark.




More information about the Python-list mailing list