Exporting events from Python COM class.

Syver Enstad syver.enstad at sensewave.com
Sat Nov 11 15:19:41 CET 2000

"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:8ujetu01u8b at news1.newsguy.com...

> A single C++ object cannot implement two _fully separate_ "IDispatch
> interfaces".

Oh yes they can, I've done it myself, you just make two classes that inherit
IDispatch that delegate to another function. You just inherit from the two
classes and implement the methods they call and you got two implementations
of IDispatch in one class.

 Here's an example that I've used myself, I just show one of the classes
because the other one is identical except it delegates to methods with other
names (The Prefix is WindowEvent instead of DocEvent).

//  DispDocEvent and DispWindowEvent, defined to
//  make sinking two IDispatch based event interfaces
//  possible. see:
//   Prof. ATL COM Programming. (Richard Grimes, Wrox)
//   p. 154. (Clashing method names).

template <class T>
class DispDocEvent : public IDispatch
         HRESULT WINAPI GetTypeInfoCount(
    UINT* pctinfo);
        HRESULT WINAPI GetTypeInfo( UINT iTInfo,
            LCID lcid,
            ITypeInfo** ppTInfo);
       HRESULT WINAPI GetIDsOfNames( REFIID riid, BSTR* rgszNames,
            UINT cNames, LCID lcid, DISPID*rgDispId);
        HRESULT WINAPI Invoke(DISPID dispIdMember,  REFIID riid,
           LCID lcid,  WORD wFlags,    DISPPARAMS*pDispParams,
           VARIANT*pVarResult,  EXCEPINFO*pExcepInfo,   UINT*puArgErr);
}; // IDispDocEvent.

template <class T>
HRESULT DispDocEvent<T>::GetTypeInfoCount(
        UINT* pctinfo)
 return static_cast<T*>(this)->DocEvent_GetTypeInfoCount(pctinfo) ;
template <class T>
HRESULT DispDocEvent<T>::GetTypeInfo( UINT iTInfo,
         LCID lcid,
         ITypeInfo** ppTInfo)
 return static_cast<T*>(this)->DocEvent_GetTypeInfo(iTInfo, lcid, ppTInfo);
template <class T>
HRESULT DispDocEvent<T>::GetIDsOfNames(
        REFIID riid,
        BSTR* rgszNames,
        UINT cNames,
        LCID lcid,
 return static_cast<T*>(this)->DocEvent_GetIDsOfNames(
  riid, rgszNames, cNames, lcid, rgDispId);
template <class T>
HRESULT DispDocEvent<T>::Invoke(
 DISPID dispIdMember,
 REFIID riid,
 LCID lcid,
 WORD wFlags,
 return static_cast<T*>(this)->DocEvent_Invoke(
  dispIdMember, riid, lcid, wFlags, pDispParams,
  pVarResult, pExcepInfo, puArgErr);

> I have a little
> collection of auxiliary COM objects for such purposes,
> called Au.Dll (it's worth its weight in gold, and contains
> AUxiliary objects to implement COM AUtomation, so...),
> which provides for that as well as a few more useful
> things.  Unfortunately, I developed it at work, for work,
> so I can't just go and publish it (I'd need a bureaucratic
> nod of approval for that -- quite a bother...) -- but I
> guess I might rewrite and publish such parts as the
> COM-identity-masker (they'd be opensourced C++ code
> using ATL 3 and MSVC++ 6) if there was interest.

That certainly sounds interesting, I can't see a use for it just now so
don't bother if you can't spare the time, but reading solutions to problems
are always interesting. Sometimes you don't know you've had a particular
problem before you see it discussed and solved by somebody else.

Keep up the good work here at comp.lang.python.

P.S. Are there any forums/newsgroups/sites for Microsoft technologies that
have anything close to the signal/noise ratio on this group? The only site I
can think of is http://www.codeproject.com, do you know of any others?

More information about the Python-list mailing list