Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem when using MAPI within a Windows Service

7 views
Skip to first unread message

Dale Remmers

unread,
Jan 10, 2011, 3:17:50 PM1/10/11
to
I have created a couple of Windows Services that send and receive
emails with MAPI, and they work OK, but after the services are started
the user can no longer open Outlook if Outlook is using a POP3 account
(I believe that this works correctly when using an Exchange account).
The error message that is displayed varies depending upon the version
of Outlook, but here is the message for Outlook 2003:

Cannot start Microsoft Outlook. Cannot open the Outlook window. The
set of folders cannot be opened. The file ...\Outlook.pst is in use
and cannot be accessed. Close any application that is using this file,
and then try again. You might need to restart your computer.

My code looks like the following:

static HRESULT OpenDefaultMessageStore(LPMAPISESSION lpMAPISession,
LPMDB * lpMDB)
{
HRESULT hRes;
LPMDB lpTempMDB = NULL;
ULONG cbDefStoreEID = 0;
LPENTRYID pDefStoreEID = NULL;

*lpMDB = NULL;

hRes = HrMAPIFindDefaultMsgStore(lpMAPISession, &cbDefStoreEID,
&pDefStoreEID);
if (hRes) {
goto quit;
}

hRes = lpMAPISession->OpenMsgStore( NULL, //Window handle for dialogs
cbDefStoreEID, pDefStoreEID, NULL,
MAPI_BEST_ACCESS | MDB_NO_DIALOG,
&lpTempMDB);
if (hRes) {
goto quit;
}

*lpMDB = lpTempMDB;
quit:
if (pDefStoreEID)
MAPIFreeBuffer(pDefStoreEID);
return hRes;
}

int MtxMapiInit(int *sessionId, char *profile, char *password, int
noMapi)
{
{
static int initialized = 0;
MtxMapiSession *p;
HRESULT hRes;
ULONG ulFlags;

MAPIINIT_0 pMAPIInit;
pMAPIInit.ulFlags = MAPI_NO_COINIT | MAPI_NT_SERVICE ;
pMAPIInit.ulVersion = MAPI_INIT_VERSION;
hRes = MAPIInitialize ( &pMAPIInit );

if (hRes) {
return ERR_MAPI_INIT;
}

// If MAPIInitialize succeeds, create a session object.
ulFlags = MAPI_NEW_SESSION |
MAPI_EXPLICIT_PROFILE |
MAPI_EXTENDED |
MAPI_NT_SERVICE;

hRes = MAPILogonEx (0L, profile, password, ulFlags, &p-
>lpMAPISession);
if (hRes) {
return ERR_MAPI_LOGON;
}

hRes = OpenDefaultMessageStore(p->lpMAPISession, &p->lpMDB,
service);
if (hRes) {
return ERR_MAPI_OPEN_MESSAGESTORE;
}
.
.
.

Am I using the wrong flags somwhere, or is my approach incorrect?

Thanks,

0 new messages