c++visual-studio-2008comnotificationsconnection-points

event notifications not received as described


Problem:

Question:

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;
};

Solution

  • SOLVED:

    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.