Dispatch, DispatchWithEvents

Thomas Heller theller at python.net
Wed Mar 10 19:17:35 CET 2004

[followup to myself...]

Thomas Heller <theller at python.net> writes:

> I'm currently reinventing the wheel ;-), implementing 'clones' for the
> win32com.client.Dispatch and DispatchWithEvents functions using ctypes.
> It works fairly well, although the more complicated data types like
> SAFEARRAY or RECORD are not yet implemented.
> The win32com.client versions of these functions require makepy support
> (for DispatchWithEvents), and create this on demand.  The ctypes
> versions don't require something similar, they are using the ITypeComp
> interface at runtime to bind methods, properties, and constants on
> demand, for events support they use either IProvideClassInfo2 to find
> the outgoing interface, or iterate through the type library to find the
> type info and finally ITypeComp for the default outgoing interface.
> For my own sake, I'm trying to keep the ctypes version as compatible as
> possible to the win32com versions, although I'm not happy by some of the
> design decisions Mark Hammond or whoever wrote this stuff made.
> First, constants defined in the type libraries are exposed in the
> win32com.client.constants instance, which is internally a sequence of
> dictionaries.  Wouldn't it be better to have the constants available in
> the object returned by the Dispatch() call itself, maybe in a _constants
> property?  I'm also wondering how VB does this...
> My second 'complaint' is about the event handlers.  It seems win32com
> prepends 'On' to the method handler names if the method itself, as
> defined in the type library, doesn't already start with 'On'.  Take
> Internetexplorer as an example.  The DWebBrowserEvents2 outgoing
> interface has methods named "BeforeNavigate2", "NavigateComplete2", and
> "OnQuit".  The handlers in Python then must be named
> "OnBeforeNavigate2", "OnNavigateComplete2", and "OnQuit".  The method
> names look nice in the Python class implementation, and their templates
> are also available as commented out code in the makepy generated files,
> but looking at the Internet Explorer type library with Oleview, I find
> this very confusing.  What is the reason that it was chosen this way?

Maybe this has to do with the fact (I didn't know this before) that
DispatchWithEvents(progid, user_event_class) returns an instance of a
class which has user_event_class as one of its base classes.  So, all
the COM methods, properties, and even the event handler methods share a
common namespace.


More information about the Python-list mailing list