Help: Capturing COM events

Jeff Shannon jeff at ccvcorp.com
Fri Jun 1 03:36:56 CEST 2001


rusha at data-tech.com (Rush) wrote in message news:<9c4a6c75.0105311112.85a330d at posting.google.com>...
> I have a COM object (activeX dll) that adds fax support.  I'm trying
> to build a simple demo in PythonWin, and I need some advice on how to
> write the code to capture my object's events.
> 
[.....snip .....]

> So, my question becomes, how do I write Python code to capture my
> object's Status Event?
> 
> Many Thanks.

Look at win32com.client.DispatchWithEvents().  

In essence--

Create a class that, for every event you're interested in, has a
method named MyClass.On<eventname>

Call DispatchWithEvents, passing it the CLSID/ProgId of the COM server you're
interested in, *and* the event-handling class object.  

DispatchWithEvents will return an object that (effectively) inherits from both
the COM server and your event-handling class, and this object's proper
methods should be called when the COM object fires an event.

This is a simplification, of course, as the framework scheme that supports 
this seems to be *very* complex.  Digging through the docstrings and comments
in win32com.client should help explain more details.  But hopefully this 
general overview will be helpful.  :)

Jeff Shannon
Technician/Programmer
Credit International



More information about the Python-list mailing list