none
How to call MAPILogonEx and OpenMsgStore so that outlook can start too RRS feed

  • Question

  • I call MAPILogonEx() with flags = MAPI_NEW_SESSION | MAPI_UNICODE | MAPI_EXPLICIT_PROFILE | MAPI_EXTENDED | MAPI_ALLOW_OTHERS

    And I call OpenMsgStore() with MAPI_BEST_ACCESS | MDB_NO_DIALOG.

    I then call Advise() to listen to new message event.

    If my program starts after Outlook or MFCMAPI, everything is fine.  However, if my program runs the first, MFCMAPI OpenMsgStore() returns error MAPI_E_FAILONEPROVIDER == 0x8004011D.  And outlook fails to start complaining that OST file is in use.

    My program does have a thread periodically calls OpenMsgStore() and

    HrGetOneProp(_messageStoreDB, PR_TEST_LINE_SPEED, &pProp);

    to check connection to the exchange server.

    What is the problem? 

    Thanks,


    Bin


    • Edited by bin lin Wednesday, August 7, 2013 4:07 PM
    Wednesday, August 7, 2013 4:01 PM

Answers

  • The security context is different when running as a service even if the login name is the same, so this will not work.

    If this is a cached profile, your advise sink won't work since the cached store will be updated only if Outlook runs. And in that case, why not move your code to an Outlook addin? This way it will share the MAPI session with Outlook.

    If you still need to run your code in a service, create an online profile dynamically instead of reusing an existing profile.

    Also, do not rely on any MAPI events, use the Incremental Change Synchronization (ICS) API instead.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, August 8, 2013 4:47 PM

All replies

  • Is your app running in the same security context as Outlook? Is either one running as administrator? Is your app a regular GUI app? Does it run as a service or a scheduled task?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, August 7, 2013 4:46 PM
  • The app is a service with the service account to be the same as exchange account.

    I am testing it by running in command window as administrator.

    By the way, I use subscribe to the event as this and I don't call messageStoreDB->Release()

    _messageStoreDB->Advise(0, 0, fnevNewMail, advisor,

                                       &connectionHandle);


    Bin


    • Edited by bin lin Wednesday, August 7, 2013 5:46 PM
    Wednesday, August 7, 2013 5:42 PM
  • The security context is different when running as a service even if the login name is the same, so this will not work.

    If this is a cached profile, your advise sink won't work since the cached store will be updated only if Outlook runs. And in that case, why not move your code to an Outlook addin? This way it will share the MAPI session with Outlook.

    If you still need to run your code in a service, create an online profile dynamically instead of reusing an existing profile.

    Also, do not rely on any MAPI events, use the Incremental Change Synchronization (ICS) API instead.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, August 8, 2013 4:47 PM