Re: IMAPIAdviseSink Problem
Okey,
I think i figured out the compilation error. I forgot a definition before the object. However i am still having some problems with the code
Code:
#define INITGUID
#define USES_IID_IMAPIAdviseSink
#include <initguid.h>
#include <MAPIguid.h>
#include <cemapi.h>
class CMapiAdviseSink : public IMAPIAdviseSink
{
protected:
LPNOTIFCALLBACK m_pfnCallback;
LPVOID m_lpvContext;
LONG m_cRef;
public:
CMapiAdviseSink( LPNOTIFCALLBACK pfnCallback, LPVOID lpvContext )
: m_pfnCallback( pfnCallback )
, m_lpvContext( lpvContext )
, m_cRef( 0 )
{
}
public:// IUnknown
STDMETHOD(QueryInterface)( REFIID riid, LPVOID FAR * ppvObj )
{
if( IID_IUnknown == riid || IID_IMAPIAdviseSink == riid )
{
*ppvObj = this;
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
STDMETHOD_(ULONG, AddRef)()
{
return InterlockedIncrement( &m_cRef );
}
STDMETHOD_(ULONG, Release)()
{
ULONG ul = InterlockedDecrement( &m_cRef );
if( 0 == ul )
delete this;
return ul;
}
public:// IMAPIAdviseSink
STDMETHOD_(ULONG, OnNotify)( ULONG cNotif,
LPNOTIFICATION lpNotifications )
{
if( m_pfnCallback )
m_pfnCallback( m_lpvContext, cNotif, lpNotifications );
return S_OK;
}
};
STDAPI HrAllocAdviseSink( LPNOTIFCALLBACK lpfnCallback, LPVOID lpvContext, LPMAPIADVISESINK* lppAdviseSink )
{
if( NULL == lppAdviseSink )
return E_INVALIDARG;
*lppAdviseSink = new CMapiAdviseSink( lpfnCallback, lpvContext );
if( NULL == *lppAdviseSink )
return E_OUTOFMEMORY;
(*lppAdviseSink)->AddRef();
return S_OK;
}
ULONG __stdcall CallBack (LPVOID lpvContext, ULONG cNotification, LPNOTIFICATION lpNotifications )
{
MessageBox(0,_T("tesT"),0,0);
return 0;
}
and use:
Code:
DWORD dwContext = 0;
CMapiAdviseSink *lppAdviseSink = new CMapiAdviseSink((LPNOTIFCALLBACK)&CallBack, &dwContext );
lppAdviseSink);
(*lppAdviseSink).AddRef();
Anyways, i tried getting any notifications but i am not breaking anywhere.
Note that htis is running on a Win Ce device, but this should be no different from a desktop environment:D
Any ideas where the mistake is?
Thx in advance.