Apr 11, 2014 at 3:35 AM
Edited Apr 11, 2014 at 10:02 AM
I have written a multithreaded console application, which fetches all contacts. Sometimes(on some machines) when this MAPI application is running, and I open the outlook, I get the following message in the Outlook.
Cannot open your default e-mail folders. the file ..outlook.pst is in use and cannot be accessed.
Following is the code snippet
//Mapiinitialize with MAPI_MULTITHREAD_NOTIFICATIONS
MAPI_EXTENDED | MAPI_NO_MAIL | MAPI_NEW_SESSION | MAPI_USE_DEFAULT,
//Open the default message store
m_lpMAPISession->OpenMsgStore(0, //Window handle for dialogs
sRows->aRow.lpProps[ePR_ENTRYID].Value.bin.cb, //size and...
(LPENTRYID)sRows->aRow.lpProps[ePR_ENTRYID].Value.bin.lpb, //value of entry to open
NULL, //Use default interface (IMsgStore) to open store
&m_lpMsgStore); //Pointer to place the store in
m_lpMsgStore->GetReceiveFolder( NULL, //Get default receive folder
&cbInbox, //Size and ...
&lpbInbox, //Value of the EntryID to be returned
NULL); //You don't care to see the class returned
m_lpMsgStore->OpenEntry( cbInbox, //Size and...
lpbInbox, //Value of the Inbox's EntryID
NULL, //We want the default interface (IMAPIFolder)
&ulObjType, //Object returned type
(LPUNKNOWN *) &m_lpInboxFolder); //Returned folder
NULL, //default interface
(LPUNKNOWN *) &lpFolder);
//read all contacts
Release all other objects
Note: I have also implemented the message loop(i.e calling HRDispatchNotifications in the main thread which calls MapiInitialize)
Any help is appreciated.
Would it happen because I keep the MessageStore Open for long? Or should I use some specific flags with OpenMsgStore??
Apr 22, 2014 at 1:17 PM
Unless you're calling into Simple MAPI, MapiLogOff isn't a MAPI function, so I assume it's something you wrote. Further, I assume in there you're calling IMAPISession::Logoff (http://msdn.microsoft.com/en-us/library/office/cc842296(v=office.15).aspx
I've found it best not to call that function. Try removing it (but otherwise releasing everything normally) and see what happens.
I am calling IMAPISession::Logoff().
I did following minor code change which seemed to have solved this issue.
- Earlier I used to release the m_lpMsgStore just before the application termination, instead I changed this implementation so that I release m_lpMsgStore at the earliest[i.e in the above case I called UlRelease(m_lpMsgStore) immediately after m_lpMsgStore->OpenEntry]
Can you please let me know in which scenarios Outlook displays the message "Cannot open your default e-mail folders. the file ..outlook.pst is in use and cannot be accessed. ".? I guess you might have access to the Outlook code.