Hi All,
I'm having problems with ex MAPI when its running from an NT service.
This is the code i'm running in the log on process.
Please... if you can see ANY problem, let me know....
void Logon(System::String* profile)
{
HRESULT hRes = -1;
LPVOID pMapiInit;
LPTSTR pprof;
FLAGS ntServiceMAPIField = MAPI_NT_SERVICE;
FLAGS mapiInitField = MAPI_NO_COINIT | MAPI_MULTITHREAD_NOTIFICATIONS;
FLAGS mapiLogonFlags = MAPI_NEW_SESSION | MAPI_NO_MAIL | MAPI_EXTENDED |
MAPI_EXPLICIT_PROFILE ;//| MAPI_PASSWORD_UI;
////////////////////////////////////////////////////////
// ***Important: Only if this module is a Service unmark the next 2 line.
mapiInitField |= ntServiceMAPIField;
mapiLogonFlags |= ntServiceMAPIField;
////////////////////////////////////////////////////////
MAPIINIT_0 MAPIINIT = { MAPI_INIT_VERSION, mapiInitField};
pMapiInit = &MAPIINIT;
if (FAILED(hRes = MAPIInitialize(pMapiInit)))
{
Marshal::ThrowExceptionForHR(hRes);
}
pprof = (char*)Marshal::StringToHGlobalAnsi(profile).ToPoi nter();
LPMAPISESSION __pin* pses = &m_pSes;
if (FAILED(hRes = MAPILogonEx((ULONG)0, pprof, NULL, mapiLogonFlags, pses)))
{
Marshal::FreeHGlobal(pprof);
Marshal::ThrowExceptionForHR(hRes);
}
m_pDefMsgStore = NULL;
Marshal::FreeHGlobal(pprof);
}
Regards,
Asaf