Error : Cannot open your default e-mail folders. the file ..outlook.pst is in use and cannot be accessed.

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

// Login

//Open the default message store        
m_lpMAPISession->OpenMsgStore(0,                                                            //Window handle for dialogs
            sRows->aRow[0].lpProps[ePR_ENTRYID].Value.bin.cb,               //size and...
            (LPENTRYID)sRows->aRow[0].lpProps[ePR_ENTRYID].Value.bin.lpb,   //value of entry to open
            NULL,                                                       //Use default interface (IMsgStore) to open store
            MDB_NO_MAIL|MDB_NO_DIALOG,                                          //Flags
            &m_lpMsgStore);                                         //Pointer to place the store in

//Open Inbox
m_lpMsgStore->GetReceiveFolder( NULL,      //Get default receive folder
            0,      //Flags
            &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)
            0,                            //Flags
            &ulObjType,                   //Object returned type
            (LPUNKNOWN *) &m_lpInboxFolder); //Returned folder      

//Get Contacts
m_lpMsgStore->OpenEntry(    cb,
            NULL,           //default interface
            (LPUNKNOWN *) &lpFolder);

//read all contacts
lpFolder->GetContentsTable(0, &lpContentsTable);


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 ( I've found it best not to call that function. Try removing it (but otherwise releasing everything normally) and see what happens.
Apr 23, 2014 at 3:10 AM
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.