Problem with DispEventAdvise

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandeepkavade
    New Member
    • Mar 2007
    • 30

    #1

    Problem with DispEventAdvise

    hi all,
    i am having a sdk with fires an event.
    i am trying to catch that event in other C++ console application,
    i have derived my CEventSink class from IDispEventImpl

    EventSink.h:

    #pragma once

    #include <atlbase.h>
    #include <atlcom.h>


    static _ATL_FUNC_INFO OnEvent = {CC_STDCALL, VT_EMPTY, 5, {VT_UI4, VT_BSTR, VT_BSTR, VT_I2, VT_BSTR}};
    class ATL_NO_VTABLE CEventSink : public IDispEventImpl< 1, CEventSink, &__uuidof(_ISou rceEvents)>
    {
    public:

    BEGIN_SINK_MAP( CEventSink)
    SINK_ENTRY_INFO (1, __uuidof(_ISour ceEvents), 1, OnEventES , &OnEvent )
    END_SINK_MAP()

    CEventSink(void );
    ~CEventSink(voi d);

    HRESULT STDMETHODCALLTY PE OnEventES (DWORD dwSession, BSTR bszFilePath, BSTR bszName, SHORT Action, BSTR bszMessage);
    };

    OnEvent method from the sdk is:

    [id(0x00000001), helpstring("met hod OnEvent ")]
    HRESULT OnEvent (
    [in] long dwSession,
    [in] BSTR bszFilePath,
    [in] BSTR bszName,
    [in] short Result,
    [in] BSTR bszMessage);


    TestApp.cpp:
    #include "stdafx.h"
    #include "eventsink. h"
    int _tmain(int argc, _TCHAR* argv[])
    {
    CoInitialize(NU LL);
    ISource *spEventFiringO bject = NULL;
    CEventSink* pEventSink = NULL;
    HRESULT hr = CoCreateInstanc e(CLSID_Source, NULL, CLSCTX_ALL, IID_ISource, reinterpret_cas t<void **>(&spEventFir ingObject));

    if(SUCCEEDED(hr ))
    {
    pEventSink = new CEventSink();
    hr = pEventSink->DispEventAdvis e(spEventFiring Object, &__uuidof(_ISou rceEvents));
    }
    CoUninitialize( );
    return 0;
    }

    but DispEventAdvise returns something like

    hr = 0xc0000005 The instruction at "0x

    what is wrong here?

    Thanx in advance.
Working...