MAPILogonComplete event not always firing

M

Mark Cote

I'm using the MAPILogonComplete event in an Outlook add-in (written in
C++) to tell when we have access to all the MAPI data. We launch
Outlook in the background when our main application starts so that the
user doesn't have to, assuming that the user has a default profile
set. However, unless I have a call to
Outlook::_NameSpace::get_CurrentUser() in OnStartupComplete(), the
MAPILoginComplete event never fires. A call to MAPILogonEx() doesn't
work here; the only thing that seems to work is the get_CurrentUser()
call. It is as though, when Outlook is in the background with a
default user, it doesn't log into MAPI until the add-in asks who the
current user is, which somehow triggers the MAPI logon to determine
the current user. This is very strange, and I have the feeling that
this call is working here only because I am omitting some other
necessary call. Any ideas?

Related to this, is MAPILogonEx() absolutely necessary in an add-in?
If so, where is the best place to put it? OnStartupComplete()?

Thanks,
Mark
 
D

Dmitry Streblechenko

You should never call MAPILogonEx from a COM add-in unless you are opening a
MAPI profile different from the one used by Outlook.
Outlook delays logging to a profile for as logn as it can. If the UI needs
to be shown or if you access something that cannot be accessed without
logging to MAPI (such as NAmespace.CurrentUser), Outlook will finally log to
a profile.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
M

Mark Cote

Okay that's more-or-less what I thought. Out of curiosity, is there
an explicit way to log onto MAPI? We want our add-in to log on
immediately, if possible; right now that happens because of a call to
NameSpace::get_CurrentUser(), but the code would probably make more
sense with a call to some function that explicitly logs on. Not too
important though.

Thanks,
Mark
 
D

Dmitry Streblechenko

You can call Namespaxe.Logon, but again, you'd be better off if your code
too would delay doing anything that requires a MAPI logon for as long as
possible.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top