How to implement sink for C++ COM event handling? -


i'm struggling understand event handling when using com. have com object interface developed 3rd party should fire events. need handle these events c++ application. far have following code setup event:

event setup (main.cpp)

 iconnectionpointcontainer* connection;  result = comobjectinterface->queryinterface(iid_iconnectionpointcontainer, (void**)&connection);  iconnectionpoint* connectionpoint;  connection->findconnectionpoint(__uuidof(_icomobjectinterfaceevents), &connectionpoint);  eventsink* sink = new eventsink();  dword cookie = 0;  connectionpoint->advise(sink, &cookie); 

my problem don't know how implement eventsink? i've seen people create simple class extends form of idispatch implementation don't seem have implementation available , can't find decent examples on how create own implementation. have 2 methods on eventsink know called:

eventsink.cpp

hresult __stdcall eventsink::queryinterface(refiid riid, void **ppv) {    *ppv = nullptr;    hresult hr = e_nointerface;    if (riid == iid_iunknown || riid == iid_idispatch ||       riid == __uuidof(_icomobjectinterfaceevents))    {        *ppv = static_cast<_icomobjectinterfaceevents *>(this); //(static_cast<idispatch*>(this));       addref();       hr = s_ok;    }    return hr; }  ulong __stdcall eventsink::addref() {    return interlockedincrement(&m_cref); } 

i'm not sure if these methods working correctly though.

additionally, how can debug this? i'm able inside com object code i've been trying find event going generated i'm unable find logically looks going produce event.

i having same problem, , figured out solution works embarcadero c++ builder. put info here: is there working example of com event handling in c++ builder?

i include .net code generate com object generates events - similar technique used debug event handling.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -