Outlook 2007 does not terminate after the MapiLogonEx

Apr 8, 2014 at 3:53 AM
Edited Apr 8, 2014 at 3:54 AM
Hi,

After looking at the MFCMapi code, I have written a Mapi application which reads all the contacts from address book. On couple of machines(Windows XP with Outlook 2007) I have found that I could not close the Outlook(i.e even after closing the Outlook, I could see the Outlook.exe process in the task manager)

After some research I found that if I just do MapiLogonEx, I am not able to close the Outlook. Currently I am using MAPI_EXTENDED | MAPI_NO_MAIL | MAPI_NEW_SESSION | MAPI_USE_DEFAULT, but I have tried most of the other combinations, and it does not seem to be working.

When I used the MfcMapi(Session->Advanced Logon ->Logon with Flags), this seemed to be working fine.

I have edited the MfcMapi code(i.e added a Sleep for 5 minutes just after the MapiLognEx function). In this case, I could not terminate the Outlook.

So, my conclusion is MfcMapi does something after MapiLogonEx, which I am not doing in my application. Can you please help me in solving this issue?

Any help is appreciated.

Note: In one of the machines I could reproduce this every time.

Regards,
Rohan
Coordinator
Apr 8, 2014 at 11:49 AM
MFCMAPI doesn't do anything in particular, but it is a windows application and as such does pump messages - MAPI needs messages to be pumped for the notification subsystem to work properly. Try pumping messages and see if that fixes the problem.
Apr 9, 2014 at 3:41 AM
Edited Apr 10, 2014 at 3:33 AM
Thank you, it worked fine after I have implemented the message loop. Earlier I had spent at least a week breaking my head on this issue.

Since I have a multithreaded console application, I had to do following changes
1) Use MAPI_MULTITHREAD_NOTIFICATIONS in MAPIInitialize
MAPIINIT_0 tMapiinit;
tMapiinit.ulVersion = MAPI_INIT_VERSION;
tMapiinit.ulFlags = MAPI_MULTITHREAD_NOTIFICATIONS;
HRESULT hr = MAPIInitialize(&tMapiinit);
2) In the main thread which has done MAPIInitialize(), kept invoking HrDispatchNotifications() in regular intervals(say every second)