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,