Outlook 2016 mapi.MAPIUninitialize() crashes RRS feed

  • Question

  • Hi,

    In my multi threaded application where multiple threads do mapi initialize by

    mapi.MAPIUninitialize() crashes. I got the following call stack from windbg.


    Each thread does only following mapi calls in sequence :
    1 MAPIInitialize -> mapi.MAPIInitialize((0, mapi.MAPI_MULTITHREAD_NOTIFICATIONS))
    2 MAPIAdminProfiles -> adminprof = mapi.MAPIAdminProfiles(0)
    3 HrQueryAllRows ->tab = self.adminprof.GetProfileTable(0)
    rows = mapi.HrQueryAllRows(tab, (PR_DEFAULT_PROFILE,PR_DISPLAY_NAME_A), None, None, 0)

    4 MAPILogonEx -> session = mapi.MAPILogonEx(0, profile, None, logonFlags)
    where logonFlgs = mapi.MAPI_NO_MAIL|mapi.MAPI_EXTENDED|mapi.MAPI_NEW_SESSION

    5 session.Logoff(0,0,0)
    6 mapi.MAPIUninitialize()

    If there are two threads T1 and T2 .
    T1 logs in to session prior to T2 and T1 does MAPIUninitialize after T2 it dont lead to crash, 
    But if T1 logs in to session prior to T2 and T1 does MAPIUninitialize before T2 then call to MAPIUninitialize leads to crash with above stack.

    PS : Crash occurs with Outlook 2016 and works fine with Outlook 2013 and prior.

    • Edited by cmits2016 Tuesday, December 1, 2015 6:40 AM
    Tuesday, December 1, 2015 6:10 AM


All replies

  • Is T1 used on the main thread and T2 on a secondary?

    Take a look at the MAPI Multithreading Rules page which states the following:

    If MAPI_MULTITHREAD_NOTIFICATIONS is not used, the first thread to call MAPIInitialize should live longer than all other MAPI threads and should be the last to call MAPIUninitialize.

    Looks like the mentioned flag doesn't play any role now and you should preserve the sequence of calls, i.e. use LIFO (last in, first out).

    Tuesday, December 1, 2015 9:47 AM
  • Thanks Eugene for the response.

    Here T1 and T2 are threads at Sibling level,created by a thread say M.

    Thread M do not do any mapi calls Hence I am not doing  mapi.MAPIInitialize  and mapi.MAPIUninitialize for thread M.

    Is this could be the issue ?


    • Edited by cmits2016 Tuesday, December 1, 2015 10:27 AM
    Tuesday, December 1, 2015 10:26 AM
  • I don't think so. Looks like the sequence plays more vital role now in Outlook 2016.
    Tuesday, December 1, 2015 10:35 AM
  • There are some more observations I would like to add

    If T1 and T2 dont do MAPILogonEx call then  mapi.MAPIUninitialize() succeeds in any sequence.

    If either of T1 or T2 do MAPILogonEx  call then the thread that had call MAPILogonEx  must do last mapi.MAPIUninitialize() of two.

    Is it the sequence of of  MAPIInitialize or MAPILogonEx call ?

    By the way Can you explain what above windbg call stack indicates.

    Tuesday, December 1, 2015 10:52 AM
    • Edited by RLWA32 Tuesday, December 1, 2015 11:44 AM
    • Marked as answer by David_JunFeng Tuesday, December 15, 2015 1:35 AM
    Tuesday, December 1, 2015 11:43 AM