Bruce Sandeman
unread,Jun 22, 2012, 5:53:06 AM6/22/12You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Hi All,
I wonder if anyone can help me out. I'm currently creating windows
service (32bit) using the MapiStubLibrary and Outlook 2010 headers
within Visual C++ 2010.
Now, this all works fine if I call the MAPI code from within the main
function (i.e. before the service pieces have taken over); this works
whether run as a service or as a command line.
If I call this same code from within the ServiceMain function then it
fails everytime with MAPI_E_LOGON_FAILED from MAPILogonEx.
The function I am calling with all the mapi code within it is as
follows.
thanks for any advice.
cheers
Bruce
int CEnveloperMapi::testMapi(Helper thehelper, char *szMapiProfile)
{
mapihelper = thehelper;
HRESULT hr = S_OK;
MAPIINIT_0 MAPIINIT= { 0, MAPI_MULTITHREAD_NOTIFICATIONS |
MAPI_NT_SERVICE};
hr = MAPIInitialize (&MAPIINIT);
if(hr == S_OK )
{ // IMAPISession Smart Pointer Context
CComPtr<IMAPISession> spSession;
hr = MAPILogonEx(NULL, szMapiProfile, NULL, MAPI_NT_SERVICE,
&spSession);
if(hr == S_OK)
{
ListStoresTable(spSession);
} else
{
mapihelper.WriteToLog("MapiLogonEx Failed");
switch(hr)
{
case MAPI_E_LOGON_FAILED : { mapihelper.WriteToLog("MapiLogonEx
Failed - MAPI_E_LOGON_FAILED"); break;};
case MAPI_E_TIMEOUT : { mapihelper.WriteToLog("MapiLogonEx Failed
- MAPI_E_TIMEOUT"); break;};
case MAPI_E_USER_CANCEL : { mapihelper.WriteToLog("MapiLogonEx
Failed - MAPI_E_USER_CANCEL"); break;};
case MAPI_E_NO_SUPPORT : { mapihelper.WriteToLog("MapiLogonEx
Failed - MAPI_E_NO_SUPPORT"); break;};
case NULL : { mapihelper.WriteToLog("MapiLogonEx - NULL result");
break;};
default : {
char shr[] = "0x999";
_ltoa(hr,shr,16);
char msg1[64] = "MapiLogonEx unknown failure [ ";
char *cat = strcat(msg1, shr);
mapihelper.WriteToLog(cat, "]");
break;
};
}
}
} else
{
switch(hr)
{
case MAPI_E_INVALID_PARAMETER :
{ mapihelper.WriteToLog("MapiInitialize Failed -
MAPI_E_INVALID_PARAMETER"); break;};
case MAPI_E_TOO_COMPLEX : { mapihelper.WriteToLog("MapiInitialize
MAPI_E_TOO_COMPLEX"); break;};
case MAPI_E_UNKNOWN_FLAGS : { mapihelper.WriteToLog("MapiInitialize
MAPI_E_UNKNOWN_FLAGS"); break;};
case MAPI_E_VERSION : { mapihelper.WriteToLog("MapiInitialize
MAPI_E_VERSION"); break;};
case MAPI_E_SESSION_LIMIT : { mapihelper.WriteToLog("MapiInitialize
MAPI_E_SESSION_LIMIT"); break;};
case MAPI_E_NOT_ENOUGH_RESOURCES :
{ mapihelper.WriteToLog("MapiInitialize MAPI_E_NOT_ENOUGH_RESOURCES");
break;};
case MAPI_E_INVALID_OBJECT :
{ mapihelper.WriteToLog("MapiInitialize MAPI_E_INVALID_OBJECT");
break;};
case MAPI_E_NOT_INITIALIZED :
{ mapihelper.WriteToLog("MapiInitialize MAPI_E_NOT_INITIALIZED");
break;};
case NULL : { mapihelper.WriteToLog("MapiInitialize NULL");
break;};
default : {
char shr[] = "0x999";
_ltoa(hr,shr,16);
char msg1[64] = "MapiInitialize unknown failure [ ";
char *cat = strcat(msg1, shr);
mapihelper.WriteToLog(cat, "]");
break;
};
}
}
MAPIUninitialize();
return 0;
}