[python-win32] COM and ActiveX controls

Geoff Schmidt gschmidt at gschmidt.org
Tue Apr 19 21:55:22 CEST 2005

Greetings --

I'm trying to embed a web browser inside a Python application. So far, 
the most straightforward avenue seems to be to use Mozilla or IE as an 
ActiveX control -- they have identical interfaces. It seems like this 
should go as follows:

1) Find the HWND of the window in which the control should appear
2) Create a stub object that implements IOleClientSite with no-op 
implementations of its methods, since we don't need them
3) Instantiate Mozilla or IE with CoCreateInstance and get the 
IOleObject interface
4) Call DoVerb on the control with the HWND, a rectangle giving the 
size and position where the control should appear, the IOleClientSite, 
5) Call SetExtent on the control as necessary in the future to resize 
it in response to parent window resizing

Then, for my application, I'll want to be able to execute Javascript in 
the context of the browser, and catch URL loads and trigger application 
events in response to them. All of these things appear to be possible 
with the IWebBrowser family of interfaces (for which I seem to have a 
nice type library, incidentally.)

The first problem I've run into is that pythoncom doesn't wrap 
IOleObject, so there's no way to make the call to DoVerb. (Nor is 
DoVerb exposed through IDispatch :)) In other words:

unk = pythoncom.CoCreateInstance("Mozilla.Browser", None, 
pythoncom.CLSCTX_INPROC, pythoncom.IID_IUnknown)
IID_IOleObject = IID('{00000112-0000-0000-C000-000000000046}')
obj = c.QueryInterface(IID_IOleObject)
-> TypeError: There is no interface object registered that supports 
this IID

A few questions:
* How hard would it be for me to put together a wrapping of IOleObject, 
IOleClientSite, and whatever else I need to embed a basic ActiveX 
* Is there some other way that I missed to do this without wrapping new 
interfaces (like some IDispatch trick?)
* Is this approach to embedding a web browser tractable at all? Is 
there as easier way? Has anyone had any luck embedding Mozilla in 
Python on win32 through a more direct mechanism, like PyXPCOM? (I 
haven't been able to find any stories about that happening on the web.)

FWIW, this is for the Windows port of the desktop video player for the 
Participatory Culture Foundation's internet TV project. Check it out at 
http://www.participatoryculture.org/. For the actual widget set, I have 
started out in PyGTK, for skinning support and to ease Linux 
portability. It's not at all hard to pull HWND's out of PyGTK. If the 
idea of embedding an ActiveX control in PyGTK seems hilariously wrong 
to you for some reason that has eluded me, do let me know :)

Thanks a lot --
Geoff Schmidt

More information about the Python-win32 mailing list