• Sign In
 
  • MSDN Blogs
  • Microsoft Blog Images
  • More ...

  • Advanced search options...
  • Blog Home
  • About
  • Email Blog Author
  • Share this
  • RSS for posts
  • Atom
  • RSS for comments
  • CDO (20)
  • Code Snippet (42)
  • Custom Providers (15)
  • Debugging (7)
  • DevMsgTeam (268)
  • Documentation (96)
  • DST (8)
  • EWS (7)
  • Exchange (98)
  • Gotchas (89)
  • Hotfix (26)
  • MAPI (212)
  • MAPI Download (47)
  • MFCMAPI (87)
  • MSDN (49)
  • Non Dev (11)
  • OOM (17)
  • Outlook (154)
  • Outlook 2007 Auxiliary Reference (44)
  • Outlook Integration API (11)
  • Protocol Docs (20)
  • PST/OST (21)
  • Public Folders (3)
  • Vista (12)
  • WrapPST (14)
Links:
  • Download MFCMAPI
  • MFCMAPI on Facebook
  • Troubleshooting Outlook Crashes
  • Office Update Center
  • Developer Messaging Team Blog
This site is provided "AS IS" with no warranties, and confers no rights. Use of included code samples are subject to the terms specified in the Terms of Use.
Archives
  • January 2012 (1)
  • December 2011 (3)
  • November 2011 (1)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (4)
  • June 2011 (3)
  • May 2011 (3)
  • April 2011 (3)
  • March 2011 (5)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (1)
  • November 2010 (4)
  • October 2010 (1)
  • September 2010 (3)
  • August 2010 (5)
  • July 2010 (3)
  • June 2010 (3)
  • May 2010 (1)
  • April 2010 (3)
  • March 2010 (3)
  • February 2010 (3)
  • January 2010 (2)
  • December 2009 (3)
  • November 2009 (5)
  • October 2009 (4)
  • September 2009 (5)
  • August 2009 (5)
  • July 2009 (11)
  • June 2009 (6)
  • May 2009 (5)
  • April 2009 (3)
  • March 2009 (18)
  • February 2009 (10)
  • January 2009 (3)
  • December 2008 (2)
  • November 2008 (2)
  • October 2008 (5)
  • September 2008 (4)
  • August 2008 (10)
  • July 2008 (6)
  • June 2008 (8)
  • May 2008 (2)
  • April 2008 (4)
  • March 2008 (2)
  • February 2008 (2)
  • January 2008 (5)
  • December 2007 (3)
  • November 2007 (2)
  • October 2007 (3)
  • September 2007 (1)
  • August 2007 (4)
  • July 2007 (5)
  • June 2007 (3)
  • May 2007 (4)
  • April 2007 (1)
  • March 2007 (6)
  • February 2007 (3)
  • January 2007 (2)
  • December 2006 (4)
  • November 2006 (3)
  • October 2006 (1)
  • August 2006 (1)
  • June 2006 (5)
  • May 2006 (5)
  • December 2005 (1)
  • November 2005 (4)
  • October 2005 (2)
  • September 2005 (1)
  • April 2005 (3)
  • December 2004 (2)
  • September 2004 (2)
  • August 2004 (3)
  • July 2004 (3)

How To Break The MAPI Stub Library

MSDN Blogs > SGriffin's MAPI Internals > How To Break The MAPI Stub Library

How To Break The MAPI Stub Library

Stephen Griffin - MSFT
3 Jun 2008 10:08 PM
  • Comments 4

Well, that didn't take long. We just released the latest MAPI download this weekend and yesterday we got a case from a customer who's application no longer functioned when they upgraded. The issue was quickly resolved, and I was asked to communicate some of the details in case anyone else runs in to it.

The important detail here is that in order to get Exchange's MAPI to work on Vista and Windows Server 2008, we had to make it work with the MAPI Stub Library. So we installed our binaries under Program Files and set the following registry keys*:

    Key Value
    HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail\ExchangeMAPI::DLLPathEx <path to exmapi32.dll>
    HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail::Default ExchangeMAPI

The first key tells the stub library where to find an Extended MAPI implementation called ExchangeMAPI, and the second key tells the stub library that when an application loads it, the default MAPI implementation to which all calls should be directed is ExchangeMAPI. In other words, when you load the stub library, it will in turn load exmapi32.dll.

This is the same as what Outlook does when it's installed - it registers itself and sets the Default key to "Microsoft Outlook".

Now, this customer had a product which had worked for years with either Outlook's or Exchange's implementation of MAPI. Apparently, they had had problems in the past with systems where Outlook was installed, but the default mail client had been set to something else, such as Hotmail. So, to work around this problem, following the advice given in Explicitly Mapping MAPI Calls to MAPI DLLs they wrote a key under HKLM\Software\Microsoft\Windows Messaging Subsystem\MSMapiApps mapping their application to the "Microsoft Outlook" implementation of MAPI. This worked on machines where Outlook was installed, since there would be a Microsoft Outlook key from which to read DLLPathEx. And on a machine where Exchange's MAPI was installed, since Exchange overwrote the stub library nothing written in any of those keys mattered.

Now, of course, it matters. When they set their application to use "Microsoft Outlook", but Outlook isn't installed, the stub doesn't know where to turn. It can't find the default mail client. It can't just start loading random MAPI binaries, so it turns to it's fallback mechanism, which is to look for MAPI32x.dll. Since that's not there either, it gives up and fails the call to MAPIInitialize.

There's not a perfect workaround here - there's no way to tell the stub that there are two MAPI implementations your application can work with and just use whichever one is available. The simplest solution here is probably to not use the MSMapiApps key and either accept whatever MAPI implementation is the default or load MAPI binaries manually and bypass the stub. The latter is what MFCMAPI does. You could also do some runtime detection of whether "Microsoft Outlook" or "ExchangeMAPI" are listed under the Mail key and set the MSMapiApps key appropriately before loading MAPI. Or, depending on where your application is meant to be installed, pick an implementation of MAPI and insist that it be the one installed with your app. No matter what you choose, this issue illustrates why I stressed to the commenter of my previous post on this update: "The move from system32 to program files is a fairly large and potentially destabilizing move though. You should definitely test your applications with this update."

*64 bit complicates this a bit by redirecting the registry keys. So for those of you playing along at home on a 64 bit box, look under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Clients\Mail

  • 4 Comments
Exchange, Outlook, MAPI, Gotchas, MFCMAPI, MAPI Download, DevMsgTeam
Comments
  • SGriffin's MAPI Internals
    30 Jul 2008 10:37 AM

    Sorry for not posting this sooner - I just found out about it today. As I noted previously , we recently

  • SGriffin's MAPI Internals
    19 Sep 2008 9:28 AM

    In a previous article , I noted that you could load exmapi32.dll directly and bypass the MAPI Stub Library.

  • Len
    25 Nov 2008 5:40 PM

    For third-party applications that explicitly loads MAPI32.dll, what's does Microsoft recommended on how to support both the mapi32.dll and exmapi32?

    i.e

    1.  Should we compile two version of the application?

    2.  Use the stub mapi32 dll?

    There was mention of a performance hit on using the stub mapi32.dll hence the Exchange server doesn't use the stub dll.  

    Are there documentation what the performance on using the mapi32?

    In regards to the stub mapi dll, is the stub dll guarantee to be install on a new server?

    Thanks.

  • Stephen Griffin - MSFT
    25 Nov 2008 7:38 PM

    If you're explicitly loading mapi, there's no reason to have two different binaries, as you can always decide what mapi to load on the fly. The Exchange MAPI download is built to use the stub library. If you want to bypass the stub and load exmapi32.dll directly, you can do that, but you'll want to wait for the fix I talk about in "Issues Loading ExMAPI32.dll Directly".

    The stub library is an OS component. It comes with Windows. So it should be there on a new server.

Page 1 of 1 (4 items)
Leave a Comment
  • Please add 1 and 8 and type the answer here:
  • Post
  • © 2012 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy Statement
  • Report Abuse
  • 5.6.131.143