[python-win32] WIN32COM: Cannot get event interface given a wrapped dispatch pointer

Brad Johnson Brad.Johnson at ballardtech.com
Fri Oct 24 02:00:49 CEST 2008


Mark Hammond <mhammond <at> skippinet.com.au> writes:

>
> Eeek.  Have you actually imported the other library, or simply copied the
> interface definition.  I'd be surprised to find the same interface defined
> in 2 typelibs (but not surprised to see cross-typelib references).
> 

I think I was a bit vague in my post. The interfaces are referenced in other
typelibs, but not defined. Unfortunately, in the gencache each one of these
references creates their own stub in its own file generated from its own
typelib. Hence, when given the IID of a dispatch pointer, the "last guy wins" in
the sense that the last typelib generated with makepy will hold the class
definition in the dictionary mapCLSIDToClass. This is okay as long as the IID is
used once, but since we refer to the IID in multiple typelibs, it breaks when
attempting to do any further introspection (like calling WithEvents).

>
> Any suggestions how we should fix this?  I'm flat out spending the little
> Python time I do have on py3k at the moment...
> 

So far all I have got is a hack which modifies GetEvents() slightly to do an
uncoditional EnsureModule() at the last possible moment using the correct
typelib info for the parameters, rather than placing it in the if statement.
This will overwrite whatever is currently in mapCLSIDToClass for the IID with
the one from its own typelib.

I call it a hack because it's slower (obviously), and because it will only work
if the dispatch interface is only used in one coclass for that typelib. If there
are any more, I don't know what will happen.

> Cheers,
> 
> Mark
> 



More information about the python-win32 mailing list