Exporting events from Python COM class.

Alex Martelli aleaxit at yahoo.com
Fri Nov 10 10:51:09 EST 2000


"Mark Hammond" <MarkH at ActiveState.com> wrote in message
news:3A0BD79B.8070505 at ActiveState.com...
    [snip]
> > This comes down to the difference between IDispatch and IID_IDispatch.
> > Its perfectly ok for an object to have two different interfaces that
> > are both IDispatch - they just need a different IID.
>
> I'm not really with you here.  The COM documentation says that you get
> back "the interface pointer requested in riid".

Yes.  And two interfaces' vtables MAY have strictly
similar binary layouts.  In particular, all (pure)
dispinterfaces have a vtable layout of 7 methods...
("dual" interfaces, being _derived_ from IDispatch,
have vtable layouts that START with the same 7
entries, followed by whatever-they-wish).


> I'm not sure how you get the implication that you can get back an
> IDispatch when iid != IID_IDispatch, or vice-versa.  The docs are very
> clear - you get back an interface for the requested IID.

Absolutely true.  So, in particular, if the IID is for
a dispinterface, you get a pointer to a vtable whose
first 7 methods happen to be that way.

> Thus, I don't see any legitimate way we can assume an IDispatch comes
> back if the IID is anything other than IID_IDispatch.  Indeed, I can see
> good reasons (such as marshalling) why you should _not_ make this
> assumption.

If the IID is for a custom interface that is not a
dispinterface, then the vtable's layout will be
utterly different (except for the first 3 methods,
of course:-).  But then we're in trouble anyway (it
would be neat to _diagnose_ that trouble otherwise
than by crashing... at least in some cases... e.g.,
check in the registry under interfaces how many
methods that interface has, and, if it's not exactly
seven, then at least we know it's no dispinterface...).


> I could see why such an exception _should_ be made for events, and I
> could believe such exceptions do exist - but I can see absolutely no
> evidence of this, in documentation or behaviour.

There is no exception whatsoever.  And it's not
strictly true that the two interfaces "are IDispatch" --
they may 'just' _have the same vtable layout for
7 methods each_...


Alex






More information about the Python-list mailing list