Issue while implementing methods of IDispatch for EventSink

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I currently have a COM interface that inherits from IDispatch and IUnknown.I am trying to create an event sink so I need to inherit from them. However in my earlier post I was told " that object only needs to implement IDispatch::Invoke (plus, of course, the three IUnknown methods). The other three IDispatch methods can simply return S_OK or E_NOTIMPL - they are never called."
Currently I have the following code for the class and I would appreciate it if the experts here can go across it and let me know if I am missing anything here since the advice method returns an S_OK. However no event is called.

class CSink : public _ISTIEventsEvents
{
private:
ULONG m_ulRefCount;
LPTYPEINFO m_ptinfoEnglish; // English type information for application interface
LPTYPEINFO m_ptinfoGerman; // German type information for application interface

//----------------- Implementation of IUnknown Methods:-------------------------------
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject)
{
if (ppvObject == NULL)
return E_POINTER;

if (riid == __uuidof(_ISTIEventsEvents) || riid == __uuidof(IUnknown))
{
*ppvObject = this;
}
else
{
*ppvObject = NULL;
return E_NOINTERFACE;
}
static_cast<IUnknown*>(*ppvObject)->AddRef();
return S_OK;
}

virtual ULONG STDMETHODCALLTYPE AddRef()
{
return ::InterlockedIncrement(&m_ulRefCount);
}

virtual ULONG STDMETHODCALLTYPE Release()
{
ULONG ulRefCount = ::InterlockedDecrement(&m_ulRefCount);

if (ulRefCount == 0)
delete this;

return ulRefCount;
}
//--------------------------------------------------------------------------------

public:
//Class Constructor
CSink() : m_ulRefCount(0) {}
~CSink() {}


//IDispatch Methods implemetation-------------------------------------------------------

STDMETHODIMP GetTypeInfoCount(UINT * pctinfo)
{
/*
if (pctinfo == NULL)
return E_INVALIDARG;

*pctinfo = 1;
return NOERROR;
*/
//return E_NOTIMPL ;
return S_OK ;
}

STDMETHODIMP GetTypeInfo( UINT itinfo, LCID lcid, ITypeInfo ** pptinfo)
{
/*
LPTYPEINFO ptinfo;

if (pptinfo == NULL)
return E_INVALIDARG;

*pptinfo = NULL;

if(itinfo != 0)
return DISP_E_BADINDEX;

if(lcid == LOCALE_SYSTEM_DEFAULT || lcid == 0)
lcid = GetSystemDefaultLCID();

if(lcid == LOCALE_USER_DEFAULT)
lcid = GetUserDefaultLCID();

switch(lcid)
{

case LCID_GERMAN:
ptinfo = m_ptinfoGerman;
break;

case LCID_ENGLISH:
ptinfo = m_ptinfoEnglish;
break;

default:
return DISP_E_UNKNOWNLCID;
}

ptinfo->AddRef();
*pptinfo = ptinfo;
return NOERROR;*/
//return E_NOTIMPL ;
return S_OK ;
}

STDMETHODIMP GetIDsOfNames(REFIID riid,OLECHAR ** rgszNames, UINT cNames, LCID lcid, DISPID * rgdispid)
{
/*
LPTYPEINFO ptinfo;

if(lcid == LOCALE_SYSTEM_DEFAULT || lcid == 0)
lcid = GetSystemDefaultLCID();

if(lcid == LOCALE_USER_DEFAULT)
lcid = GetUserDefaultLCID();

switch(lcid)
{

case LCID_GERMAN:
ptinfo = m_ptinfoGerman;
break;

case LCID_ENGLISH:
ptinfo = m_ptinfoEnglish;
break;

default:
return DISP_E_UNKNOWNLCID;
}
// We are delegating input validation to DispGetIDsOfNames.
// Real-world applications may require additional validation.
return DispGetIDsOfNames(ptinfo, rgszNames, cNames, rgdispid);
*/
//return E_NOTIMPL ;
return S_OK ;
}

STDMETHODIMP Invoke( DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, UINT * puArgErr)
{
// We are delegating input validation to DispInvoke.
// Real-world applications may require additional validation.

return DispInvoke( this, m_ptinfoEnglish,dispidMember, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
}
//--------------------------------------------------------------------------------------



The above class only contains the implementation of necessary inherited methods. I did not mention the event methods here since none of the events are being triggered. Also here is how I am subscribing to the events hr = conn_point->Advise(snk,&cookie);

if(hr==S_OK)
{
SendOrder();
}
else
{
__debugbreak();
}

std::cout << "Waiting for event";
std::cin.get();Any suggestions on what I miht be doing wrong or something that I should try ?









A candle loses nothing by lighting another candle.

View the full article
 
Back
Top