Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Problem with DispEventAdvise

Problem with DispEventAdvise

Scheduled Pinned Locked Moved ATL / WTL / STL
c++questionhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sandeepkavade
    wrote on last edited by
    #1

    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.

    S 1 Reply Last reply
    0
    • S sandeepkavade

      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.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      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
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups