Problem:
Event notifications (From COM object - Server) are not received as listed in the Sink (class) implementation.
One event notification is received (Event_one), however, others are not received accordingly
If order is changed - in IDispatch::Invoke, that is:
Event_one
is swapped to Event_two
then Event_two
notification received but Event_one
and others neglected accordinglyQuestion:
Note:
For instance (example):
Illustration of IDispatch::Invoke - taken from Sink Class:
HRESULT STDMETHODCALLTYPE Invoke(
{
//omitted parameters
// The riid parameter is always supposed to be IID_NULL
if (riid != IID_NULL)
return DISP_E_UNKNOWNINTERFACE;
if (pDispParams) //DISPID dispIdMember
{
switch (dispIdMember) {
case 1:
return Event_one();
case 2:
return Event_two();
case 3:
return Event_three();
default:
return E_NOTIMPL;
}
}
return E_NOTIMPL;
}
Illustration of QueryInterface:
STDMETHOD (QueryInterface)(
//omitted parameters
{
if (iid == IID_IUnknown || iid == __uuidof(IEvents))
{
*ppvObject = (IEvents *)this;
} else {
*ppvObject = NULL;
return E_NOINTERFACE;
}
m_dwRefCount++;
return S_OK;
};
After reviewing the corresponding IDL FILE (generated by the MIDL compiler), it was evident that each method contained in the IEvent interface, has a unique ID. For instance, Event_one
has an ID of 2. For example:
methods:
[id(0x00000002)]
HRESULT Event_one();
Therefore, making a change as followings - in the IDispatch::invoke implementation (illustrated in the above question):
//omitted
if (pDispParams) //DISPID dispIdMember
{
switch (dispIdMember) {
case 2:
return Event_one();
//omitted
Now when invoked accordingly, the desired/correct method is now executed.