Click to See Complete Forum and Search --> : Dynamic Event Handlers


Amitava Shee
April 13th, 1999, 12:26 AM
Hi all :

How do you dynamically create an event handler for a COM object ? Specifically, I need to create a vtable dynamically so that it implements dual interface (event) described by the type library of the COM server. This is much like what VB does when it generates a skeleton event handler for any arbitrary COM object.

Any help is greatly appreciated.

Regards,
Amitava
CA-TCG Software Pvt. Ltd.

mihai
April 16th, 1999, 03:07 AM
See IConnectionPoint::Advise, Unadvise. Ask target for IConnectionPointContainer, find your event, and then Advise. Don't forget to Undavise.
Sincerely, Mihai

Amitava Shee
April 16th, 1999, 06:34 AM
Hi Mihai :

I was actually referring to runtime synthesis of a vtable so that I could create a sink implementation on the fly.

Let's say I discover (at runtime) that CLSID_XX has an event interface IID_ISomething & it is defined as follows :

interface ISomething : IDispatch
{
HRESULT OnSomething();
}

However, I've no way of having a pre-defined ISomething implementation. I could ofcourse have a generic IDispatch implementation. However, for the connection point to work, this implementation must succeed when IID_ISomething is queried for .
IConnectionPoint::Advise() queries for the interface it represents. But then I am breaking the contract that ISomething promised namely that of supporting OnSomething() as a valid vtable entry. Ofcourse, if the server never calls through the vtable and always uses IDispatch::Invoke() instead, everything is kosher.

I know VB does that. The question is how ?

Regards,
Amitava