From: Sylvester on
Hello,

I need to register for the event "fnewObjectCreated" (creation of a message)
in my Inbox folder but the Advise method needs an alocated IMAPIAdviseSink
object.
If I write LPMAPIADVISESINK lpAdviseSink I get a warning that an
uninitialized parameter is used. That's ok because I created a pointer to
IMAPIAdviseSink Interface only. But how can I initialize lpAdviseSink?????

RESULT =
lppMDB->Advise(cbEntryID,(LPENTRYID)rgprops[0].Value.bin.lpb,fnevObjectCreat
ed,lpAdviseSink,&ulong);

please help thanks in advance

Is there a good book available for either CEMAPI or MAPI?


From: Sylvester on
I derived from IMAPIAdviseSync but my OnNotify will not dispatched.
my code is the following and after a call to Advise RESULT has value
2147942487
what makes my code wrong?

please help


void CMainDlg::OnRegisterNotification()
{

HRESULT RESULT;
LPMAPISESSION lppSession;
LPMAPITABLE lppTable;
SizedSPropTagArray(2, mSPropTagArray) =
{2,{PR_DISPLAY_NAME,PR_ENTRYID}};//PR_DISPLAY_NAME,
LPSRowSet pRows = NULL;
LPSPropValue rgprops = NULL;
LPMDB lppMDB;
ULONG ulong = 1;
ULONG cbEntryID = sizeof(ENTRYID);
ULONG rgTags[2] = {1,PR_CE_IPM_INBOX_ENTRYID};
ULONG cValues = 0;
ULONG lpulCount = 0;

ULONG cbSize = sizeof(IMAPIAdviseSink);
CNotify *lpAdviseSink = new CNotify;


while(TRUE)
{

RESULT = MAPIInitialize(0);
if(!(MB_OK == RESULT))
break;

RESULT = MAPILogonEx(0,_T(""),_T(""),0,&lppSession);
if(!(MB_OK == RESULT))
break;

RESULT = lppSession->GetMsgStoresTable (MAPI_UNICODE,&lppTable);
if(!(MB_OK == RESULT))
break;

RESULT = lppTable->SetColumns((LPSPropTagArray)&mSPropTagArray, 0);
if(!(MB_OK == RESULT))
break;
CString msgstorename=_T(CUSTOM_EMAIL_ACCOUNT_NAME);
while (TRUE)
{
LPSPropValue lpProp;

RESULT = lppTable->QueryRows(1, 0, &pRows);

if(!(MB_OK == RESULT))
goto logoff;

if (pRows->cRows != 1)
{

goto logoff;

}

lpProp = &pRows->aRow[0].lpProps[0];
// check name
if(_tcscmp(lpProp->Value.LPSZ, (LPCTSTR)msgstorename) == 0)
{
goto setAdvise; // messagestore exists
}

// free this row
FreeProwsP(pRows);
}


setAdvise:
RESULT =
lppSession->OpenMsgStore(0,pRows->aRow[0].lpProps[1].Value.bin.cb,(ENTRYID*)
pRows->aRow[0].lpProps[1].Value.bin.lpb,NULL,MDB_NO_DIALOG|MAPI_BEST_ACCESS,
&lppMDB);
if(!(MB_OK == RESULT))
break;
RESULT = lppMDB->GetProps((LPSPropTagArray) rgTags, MAPI_UNICODE,
&cValues, &rgprops);
if(!(MB_OK == RESULT))
break;
/*

CbNewENTRYID(cbEntryID);
RESULT =
lppMDB->Advise(cbEntryID,(LPENTRYID)rgprops[0].Value.bin.lpb,fnevObjectMoved
,lpAdviseSink,&ulong);

logoff:
RESULT = lppSession->Logoff(0,MAPI_LOGOFF_SHARED,0);
if(!(MB_OK == RESULT))
break;
MAPIUninitialize();
break;
}

"Nathan Lewis" <a-nlewis(a)online.microsoft.com> schrieb im Newsbeitrag
news:TOpZLMFFFHA.952(a)TK2MSFTNGXA01.phx.gbl...
> I'm no MAPI expert, but I think on the desktop you would do something like
> this:
>
> LPMAPIADVISESINK pAdviseSink = NULL;
> HRESULT hR = HrAllocAdviseSink( YourCallbackFunc, lpvSomeParam,
> &pAdviseSink );
>
> if( SUCCEEDED( hR ) )
> {
> hR = lppMDB->Advise( lcbEntryID,
> (LPENTRYID)rgprops[0].Value.bin.lpb,
> fnevObjectCreated, pAdviseSink, &ulong );
> }
>
> But since HrAllocAdviseSink doesn't seem to be implemented for Windows CE,
> I think you'll have to implement the IMAPIAdviseSink interface yourself.
> That complicates things a bit, but it shouldn't be too difficult. Here is
> a *really* simplistic - and completely untested - implementation you could
> try:
>
> #define USES_IID_IMAPIAdviseSink
> #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;
> }
> };
>
>
> You could also implement the HrAllocAdviseSink function yourself, like so:
>
> 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;
> }
>
>
> Then just throw all of this in a separate header file, and you'll end up
> with code that will compile for either the desktop or Windows CE.
> Theoretically, anyway - as I said, I haven't actually tested this code.
> Give it a shot and let me know how it works out...
>
>
> ---
>
> Nathan Lewis
> Microsoft Mobile and Embedded Devices Developer Support
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
>
>
> --------------------
> From: "Sylvester" <lists_sebastian(a)yahoo.de>
> Subject: IMsgStore::Advise
> Date: Wed, 16 Feb 2005 15:09:53 +0100
>
>
> Hello,
>
> I need to register for the event "fnewObjectCreated" (creation of a
message)
> in my Inbox folder but the Advise method needs an alocated IMAPIAdviseSink
> object.
> If I write LPMAPIADVISESINK lpAdviseSink I get a warning that an
> uninitialized parameter is used. That's ok because I created a pointer to
> IMAPIAdviseSink Interface only. But how can I initialize lpAdviseSink?????
>
> RESULT =
>
lppMDB->Advise(cbEntryID,(LPENTRYID)rgprops[0].Value.bin.lpb,fnevObjectCreat
> ed,lpAdviseSink,&ulong);
>
> please help thanks in advance
>
> Is there a good book available for either CEMAPI or MAPI?
>
>
>


From: Nathan Lewis on
That error code corresponds to "The parameter is incorrect". Looking at
the documentation for the IMsgStore::Advise method
(http://msdn.microsoft.com/library/en-us/APISP/html/sp__mapi1book_imsgstore_
advise.asp), it looks like the first parameter must be set to zero, and the
second must be set to NULL.


---

Nathan Lewis
Microsoft Mobile and Embedded Devices Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
From: "Sylvester" <lists_sebastian(a)yahoo.de>
Subject: Re: IMsgStore::Advise
Date: Thu, 17 Feb 2005 12:38:56 +0100


I derived from IMAPIAdviseSync but my OnNotify will not dispatched.
my code is the following and after a call to Advise RESULT has value
2147942487
what makes my code wrong?

please help


void CMainDlg::OnRegisterNotification()
{

HRESULT RESULT;
LPMAPISESSION lppSession;
LPMAPITABLE lppTable;
SizedSPropTagArray(2, mSPropTagArray) =
{2,{PR_DISPLAY_NAME,PR_ENTRYID}};//PR_DISPLAY_NAME,
LPSRowSet pRows = NULL;
LPSPropValue rgprops = NULL;
LPMDB lppMDB;
ULONG ulong = 1;
ULONG cbEntryID = sizeof(ENTRYID);
ULONG rgTags[2] = {1,PR_CE_IPM_INBOX_ENTRYID};
ULONG cValues = 0;
ULONG lpulCount = 0;

ULONG cbSize = sizeof(IMAPIAdviseSink);
CNotify *lpAdviseSink = new CNotify;


while(TRUE)
{

RESULT = MAPIInitialize(0);
if(!(MB_OK == RESULT))
break;

RESULT = MAPILogonEx(0,_T(""),_T(""),0,&lppSession);
if(!(MB_OK == RESULT))
break;

RESULT = lppSession->GetMsgStoresTable (MAPI_UNICODE,&lppTable);
if(!(MB_OK == RESULT))
break;

RESULT = lppTable->SetColumns((LPSPropTagArray)&mSPropTagArray, 0);
if(!(MB_OK == RESULT))
break;
CString msgstorename=_T(CUSTOM_EMAIL_ACCOUNT_NAME);
while (TRUE)
{
LPSPropValue lpProp;

RESULT = lppTable->QueryRows(1, 0, &pRows);

if(!(MB_OK == RESULT))
goto logoff;

if (pRows->cRows != 1)
{

goto logoff;

}

lpProp = &pRows->aRow[0].lpProps[0];
// check name
if(_tcscmp(lpProp->Value.LPSZ, (LPCTSTR)msgstorename) == 0)
{
goto setAdvise; // messagestore exists
}

// free this row
FreeProwsP(pRows);
}


setAdvise:
RESULT =
lppSession->OpenMsgStore(0,pRows->aRow[0].lpProps[1].Value.bin.cb,(ENTRYID*)
pRows->aRow[0].lpProps[1].Value.bin.lpb,NULL,MDB_NO_DIALOG|MAPI_BEST_ACCESS,
&lppMDB);
if(!(MB_OK == RESULT))
break;
RESULT = lppMDB->GetProps((LPSPropTagArray) rgTags, MAPI_UNICODE,
&cValues, &rgprops);
if(!(MB_OK == RESULT))
break;
/*

CbNewENTRYID(cbEntryID);
RESULT =
lppMDB->Advise(cbEntryID,(LPENTRYID)rgprops[0].Value.bin.lpb,fnevObjectMoved
,lpAdviseSink,&ulong);

logoff:
RESULT = lppSession->Logoff(0,MAPI_LOGOFF_SHARED,0);
if(!(MB_OK == RESULT))
break;
MAPIUninitialize();
break;
}

"Nathan Lewis" <a-nlewis(a)online.microsoft.com> schrieb im Newsbeitrag
news:TOpZLMFFFHA.952(a)TK2MSFTNGXA01.phx.gbl...
> I'm no MAPI expert, but I think on the desktop you would do something like
> this:
>
> LPMAPIADVISESINK pAdviseSink = NULL;
> HRESULT hR = HrAllocAdviseSink( YourCallbackFunc, lpvSomeParam,
> &pAdviseSink );
>
> if( SUCCEEDED( hR ) )
> {
> hR = lppMDB->Advise( lcbEntryID,
> (LPENTRYID)rgprops[0].Value.bin.lpb,
> fnevObjectCreated, pAdviseSink, &ulong );
> }
>
> But since HrAllocAdviseSink doesn't seem to be implemented for Windows CE,
> I think you'll have to implement the IMAPIAdviseSink interface yourself.
> That complicates things a bit, but it shouldn't be too difficult. Here is
> a *really* simplistic - and completely untested - implementation you could
> try:
>
> #define USES_IID_IMAPIAdviseSink
> #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;
> }
> };
>
>
> You could also implement the HrAllocAdviseSink function yourself, like so:
>
> 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;
> }
>
>
> Then just throw all of this in a separate header file, and you'll end up
> with code that will compile for either the desktop or Windows CE.
> Theoretically, anyway - as I said, I haven't actually tested this code.
> Give it a shot and let me know how it works out...
>
>
> ---
>
> Nathan Lewis
> Microsoft Mobile and Embedded Devices Developer Support
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
>
>
> --------------------
> From: "Sylvester" <lists_sebastian(a)yahoo.de>
> Subject: IMsgStore::Advise
> Date: Wed, 16 Feb 2005 15:09:53 +0100
>
>
> Hello,
>
> I need to register for the event "fnewObjectCreated" (creation of a
message)
> in my Inbox folder but the Advise method needs an alocated IMAPIAdviseSink
> object.
> If I write LPMAPIADVISESINK lpAdviseSink I get a warning that an
> uninitialized parameter is used. That's ok because I created a pointer to
> IMAPIAdviseSink Interface only. But how can I initialize lpAdviseSink?????
>
> RESULT =
>
lppMDB->Advise(cbEntryID,(LPENTRYID)rgprops[0].Value.bin.lpb,fnevObjectCreat
> ed,lpAdviseSink,&ulong);
>
> please help thanks in advance
>
> Is there a good book available for either CEMAPI or MAPI?
>
>
>


From: Sylvester on
i found a possible solution but I'm not sure wether it is functional or not
ULONG cbSize = sizeof(IMAPIAdviseSink);
LPMAPIADVISESINK lpAdviseSink;
MAPIAllocateBuffer(cbSize, (LPVOID*)&lpAdviseSink);

can I do something like this?

but now Advise is giving me an ErrorCode which I cannot interpret because in
help he is not documented HRESULT has the value2147942487...

please help

"Sylvester" <lists_sebastian(a)yahoo.de> schrieb im Newsbeitrag
news:eaVMxEDFFHA.3928(a)TK2MSFTNGP15.phx.gbl...
> Hello,
>
> I need to register for the event "fnewObjectCreated" (creation of a
message)
> in my Inbox folder but the Advise method needs an alocated IMAPIAdviseSink
> object.
> If I write LPMAPIADVISESINK lpAdviseSink I get a warning that an
> uninitialized parameter is used. That's ok because I created a pointer to
> IMAPIAdviseSink Interface only. But how can I initialize lpAdviseSink?????
>
> RESULT =
>
lppMDB->Advise(cbEntryID,(LPENTRYID)rgprops[0].Value.bin.lpb,fnevObjectCreat
> ed,lpAdviseSink,&ulong);
>
> please help thanks in advance
>
> Is there a good book available for either CEMAPI or MAPI?
>
>


From: Nathan Lewis on
I'm no MAPI expert, but I think on the desktop you would do something like
this:

LPMAPIADVISESINK pAdviseSink = NULL;
HRESULT hR = HrAllocAdviseSink( YourCallbackFunc, lpvSomeParam,
&pAdviseSink );

if( SUCCEEDED( hR ) )
{
hR = lppMDB->Advise( lcbEntryID,
(LPENTRYID)rgprops[0].Value.bin.lpb,
fnevObjectCreated, pAdviseSink, &ulong );
}

But since HrAllocAdviseSink doesn't seem to be implemented for Windows CE,
I think you'll have to implement the IMAPIAdviseSink interface yourself.
That complicates things a bit, but it shouldn't be too difficult. Here is
a *really* simplistic - and completely untested - implementation you could
try:

#define USES_IID_IMAPIAdviseSink
#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;
}
};


You could also implement the HrAllocAdviseSink function yourself, like so:

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;
}


Then just throw all of this in a separate header file, and you'll end up
with code that will compile for either the desktop or Windows CE.
Theoretically, anyway - as I said, I haven't actually tested this code.
Give it a shot and let me know how it works out...


---

Nathan Lewis
Microsoft Mobile and Embedded Devices Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
From: "Sylvester" <lists_sebastian(a)yahoo.de>
Subject: IMsgStore::Advise
Date: Wed, 16 Feb 2005 15:09:53 +0100


Hello,

I need to register for the event "fnewObjectCreated" (creation of a message)
in my Inbox folder but the Advise method needs an alocated IMAPIAdviseSink
object.
If I write LPMAPIADVISESINK lpAdviseSink I get a warning that an
uninitialized parameter is used. That's ok because I created a pointer to
IMAPIAdviseSink Interface only. But how can I initialize lpAdviseSink?????

RESULT =
lppMDB->Advise(cbEntryID,(LPENTRYID)rgprops[0].Value.bin.lpb,fnevObjectCreat
ed,lpAdviseSink,&ulong);

please help thanks in advance

Is there a good book available for either CEMAPI or MAPI?