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 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(_ISourceEvents)> { public: BEGIN_SINK_MAP(CEventSink) SINK_ENTRY_INFO(1, __uuidof(_ISourceEvents), 1, OnEventES , &OnEvent ) END_SINK_MAP() CEventSink(void); ~CEventSink(void); HRESULT STDMETHODCALLTYPE OnEventES (DWORD dwSession, BSTR bszFilePath, BSTR bszName, SHORT Action, BSTR bszMessage); }; OnEvent method from the sdk is: [id(0x00000001), helpstring("method 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(NULL); ISource *spEventFiringObject = NULL; CEventSink* pEventSink = NULL; HRESULT hr = CoCreateInstance(CLSID_Source, NULL, CLSCTX_ALL, IID_ISource, reinterpret_cast(&spEventFiringObject)); if(SUCCEEDED(hr)) { pEventSink = new CEventSink(); hr = pEventSink->DispEventAdvise(spEventFiringObject, &__uuidof(_ISourceEvents)); } CoUninitialize(); return 0; } but DispEventAdvise returns something like hr = 0xc0000005 The instruction at "0x what is wrong here? Thanx in advance.
-
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 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(_ISourceEvents)> { public: BEGIN_SINK_MAP(CEventSink) SINK_ENTRY_INFO(1, __uuidof(_ISourceEvents), 1, OnEventES , &OnEvent ) END_SINK_MAP() CEventSink(void); ~CEventSink(void); HRESULT STDMETHODCALLTYPE OnEventES (DWORD dwSession, BSTR bszFilePath, BSTR bszName, SHORT Action, BSTR bszMessage); }; OnEvent method from the sdk is: [id(0x00000001), helpstring("method 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(NULL); ISource *spEventFiringObject = NULL; CEventSink* pEventSink = NULL; HRESULT hr = CoCreateInstance(CLSID_Source, NULL, CLSCTX_ALL, IID_ISource, reinterpret_cast(&spEventFiringObject)); if(SUCCEEDED(hr)) { pEventSink = new CEventSink(); hr = pEventSink->DispEventAdvise(spEventFiringObject, &__uuidof(_ISourceEvents)); } CoUninitialize(); return 0; } but DispEventAdvise returns something like hr = 0xc0000005 The instruction at "0x what is wrong here? Thanx in advance.
Is the event interface defined as a dispinterface or a dual interface? It ought to be a dispinterface, really - I think dual interfaces can cause access violations (which is what your error looks like) if used as an event sink. I'd also suggest adding the following two lines to your stdafx.h before any ATL files are included. They will show (in the debug output window - you need to run your application with the debugger) when AddRef/Release and QueryInterface are called, which may help you debug your issue.
#define _ATL_DEBUG_QI #define _ATL_DEBUG_INTERFACES