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

  • About
  • Email Blog Author
  • RSS for posts
  • Atom
  • RSS for comments
    • OK
  • CDO (25)
  • Code Snippet (43)
  • Custom Providers (17)
  • Debugging (7)
  • DevMsgTeam (301)
  • Documentation (109)
  • DST (8)
  • EWS (7)
  • Exchange (109)
  • Gotchas (97)
  • Hotfix (28)
  • MAPI (240)
  • MAPI Download (54)
  • MFCMAPI (101)
  • MSDN (59)
  • Non Dev (11)
  • OOM (17)
  • Outlook (171)
  • Outlook 2007 Auxiliary Reference (45)
  • Outlook Integration API (12)
  • Protocol Docs (20)
  • PST/OST (23)
  • Referrals (8)
  • Vista (12)
  • WrapPST (18)
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
  • May 2013 (3)
  • April 2013 (1)
  • March 2013 (2)
  • February 2013 (2)
  • January 2013 (2)
  • December 2012 (4)
  • November 2012 (2)
  • October 2012 (2)
  • September 2012 (1)
  • August 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (3)
  • March 2012 (3)
  • February 2012 (3)
  • 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)
Blogs I Read
  • Exchange

  • Raymond Chen [MSFT]

  • Larry Osterman [MSFT]

  • Peter David

  • Aaron Margosis [MSFT]

  • Jason Johnston [MSFT]

  • Matt Stehle (MSFT)

  • Patrick Creehan [MSFT]

  • Ryan Gregg [MSFT]

    Outlook PM
  • WebDav 101

    Dan Bagley (MSFT)
  • Dave Vespa [MSFT]

  • Randy Topken

    Outlook EE

January, 2007

MSDN Blogs > SGriffin's MAPI Internals > January, 2007
  • Subscribe via RSS
Sort by: Most Recent | Most Views | Most Comments
Excerpt View | Full Post View
  • SGriffin's MAPI Internals

    Where did MAPISVC.INF go?

    Posted over 6 years ago
    by Stephen Griffin - MSFT
    • 18 Comments

    [This is now documented here: http://msdn.microsoft.com/en-us/library/bb820993.aspx]

    There's a KB article (http://support.microsoft.com/kb/229700) that discusses how to use FGetComponentPath to find MAPISVC.INF. It has two major problems:

    • It doesn't work well in most non-English locales
    • It doesn't work at all with Outlook 2007

    The code below corrects both problems. Here's why:

    Non-English

    I'll admit - I never fully understood this before. The documentation for FGetComponentPath indicates the szQualifier should be "(t)he MSIApplicationLCID or MSIOfficeLCID subkey described in Setting Up the MSI Keys for Your MAPI DLL." I must have skimmed over that comment hundreds of times before it sunk in. It means to go get those keys and pass what's in them to FGetComponentPath! This will allow FGetComponentPath to use the data in those keys to help locate where the localized copy of the component (MAPI) was installed. If szQualifier is left out, it will try to find the installed component using the system's default user LCID, then the system's default LCID, then a hard coded value of 1033 (English-US). This is why the code in the article would work in English locales but not elsewhere.

    Outlook 2007

    Here, again, it pays to read the documentation for FGetComponentPath (something I'm guilty of not doing). It says szComponent should be "(t)he MSIComponentID reg key described in Mapi32.dll Stub Registry Settings." The code in the article ignored this and instead passed "{473FF9A0-D659-11D1-A4B2-006008AF820E}", which was the component ID of MAPISVC.INF on Outlook 2000. This worked fine when the article was written, and continued to work up through Outlook 2003. However, Outlook 2007 no longer installs MAPISVC.INF (though it will use it if it finds it), so this component ID stops working. The fix is to pass "{FF1D0740-D227-11D1-A4B0-006008AF820E}", which is the component ID of MAPI that you'd get if you read the MSIComponentID key. In the code below, I hard coded this ID, but it would be better to try and read it from the registry first and only fall back to the hard coded string on failure.

    This code should work with all versions of Outlook, but I've only tested it with Outlook 2003 and 2007.

    // HrGetRegMultiSZValueA
    // Get a REG_MULTI_SZ registry value - allocating memory using new to hold it.
    void HrGetRegMultiSZValueA(
       IN HKEY hKey, // the key.
       IN LPCSTR lpszValue, // value name in key.
       OUT LPVOID* lppData) // where to put the data.
    {
       *lppData = NULL;
       DWORD dwKeyType = NULL;      
       DWORD cb = NULL;
       LONG lRet = 0;
       
       // Get its size
       lRet = RegQueryValueExA(
          hKey,
          lpszValue,
          NULL,
          &dwKeyType,
          NULL,
          &cb);
    
       if (ERROR_SUCCESS == lRet && cb && REG_MULTI_SZ == dwKeyType)
       {
          *lppData = new BYTE[cb];
          
          if (*lppData)
          {
             // Get the current value
             lRet = RegQueryValueExA(
                hKey, 
                lpszValue, 
                NULL, 
                &dwKeyType, 
                (unsigned char*)*lppData, 
                &cb);
             
             if (ERROR_SUCCESS != lRet)
             {
                delete[] *lppData;
                *lppData = NULL;
             }
          }
       }
    }
    
    typedef BOOL (STDAPICALLTYPE FGETCOMPONENTPATH)
    (LPSTR szComponent,
     LPSTR szQualifier,
     LPSTR szDllPath,
     DWORD cchBufferSize,
     BOOL fInstall);
    typedef FGETCOMPONENTPATH FAR * LPFGETCOMPONENTPATH; 
    
    ///////////////////////////////////////////////////////////////////////////////
    // Function name   : GetMAPISVCPath
    // Description       : This will get the correct path to the MAPISVC.INF file.
    // Return type      : void 
    // Argument         : LPSTR szMAPIDir - Buffer to hold the path to the MAPISVC file.
    //                    ULONG cchMAPIDir - size of the buffer
    void GetMAPISVCPath(LPSTR szMAPIDir, ULONG cchMAPIDir)
    {
       HRESULT hRes = S_OK;
       UINT uiRet = 0;
       LONG lRet = 0;
       BOOL bRet = true;
       
       szMAPIDir[0] = '\0'; // Terminate String at pos 0 (safer if we fail below)
       
       CHAR szSystemDir[MAX_PATH+1] = {0};
       
       // Get the system directory path
       // (mapistub.dll and mapi32.dll reside here)
       uiRet = GetSystemDirectoryA(szSystemDir, MAX_PATH);
       if (uiRet > 0)
       {
          CHAR szDLLPath[MAX_PATH+1] = {0};
          
          hRes = StringCchPrintfA(szDLLPath, MAX_PATH+1, "%s\\%s", 
             szSystemDir, "mapistub.dll");
          if (SUCCEEDED(hRes))
          {
             LPFGETCOMPONENTPATH pfnFGetComponentPath = NULL;
             
             HMODULE hmodStub = 0;
             HMODULE hmodMapi32 = 0;
             
             // Load mapistub.dll
             hmodStub = LoadLibraryA(szDLLPath);
             if (hmodStub)
             {   
                // Get the address of FGetComponentPath from the mapistub
                pfnFGetComponentPath = (LPFGETCOMPONENTPATH)GetProcAddress(
                   hmodStub, "FGetComponentPath");
             }
             
             // If we didn't get the address of FGetComponentPath
             // try mapi32.dll
             if (!pfnFGetComponentPath)
             {
                hRes = StringCchPrintfA(szDLLPath, MAX_PATH+1, "%s\\%s",
                   szSystemDir, "mapi32.dll");
                if (SUCCEEDED(hRes))
                {
                   // Load mapi32.dll
                   hmodMapi32 = LoadLibraryA(szDLLPath);
                   if (hmodMapi32)
                   {
                      // Get the address of FGetComponentPath from mapi32
                      pfnFGetComponentPath = (LPFGETCOMPONENTPATH)GetProcAddress(
                         hmodMapi32, "FGetComponentPath");
                   }
                }
             }
             if (pfnFGetComponentPath)
             {
                LPSTR szAppLCID = NULL;
                LPSTR szOfficeLCID = NULL;
                HKEY hMicrosoftOutlook = NULL;
                
                lRet = RegOpenKeyEx(
                   HKEY_LOCAL_MACHINE,
                   _T("Software\\Clients\\Mail\\Microsoft Outlook"),
                   NULL,
                   KEY_READ,
                   &hMicrosoftOutlook);
                
                if (ERROR_SUCCESS == lRet && hMicrosoftOutlook)
                {
                   HrGetRegMultiSZValueA(hMicrosoftOutlook, "MSIApplicationLCID", (LPVOID*) &szAppLCID);
                   HrGetRegMultiSZValueA(hMicrosoftOutlook, "MSIOfficeLCID", (LPVOID*) &szOfficeLCID);
                }
                
                if (szAppLCID)
                {
                   bRet = pfnFGetComponentPath(
                      "{FF1D0740-D227-11D1-A4B0-006008AF820E}", szAppLCID, szMAPIDir, cchMAPIDir, true);
                }
                if ((!bRet || szMAPIDir[0] == _T('\0')) && szOfficeLCID)
                {
                   bRet = pfnFGetComponentPath(
                      "{FF1D0740-D227-11D1-A4B0-006008AF820E}", szOfficeLCID, szMAPIDir, cchMAPIDir, true);
                }
                if (!bRet || szMAPIDir[0] == _T('\0'))
                {
                   bRet = pfnFGetComponentPath(
                      "{FF1D0740-D227-11D1-A4B0-006008AF820E}", NULL, szMAPIDir, cchMAPIDir, true);
                }
                
                // We got the path to msmapi32.dll - need to strip it
                if (bRet && szMAPIDir[0] != _T('\0'))
                {
                   LPSTR lpszSlash = NULL;
                   LPSTR lpszCur = szMAPIDir;
                   
                   for (lpszSlash = lpszCur; *lpszCur; lpszCur = lpszCur++)
                   {
                      if (*lpszCur == _T('\\')) lpszSlash = lpszCur;
                   }
                   *lpszSlash = _T('\0');
                }
    
                delete[] szOfficeLCID;
                delete[] szAppLCID;
                if (hMicrosoftOutlook) RegCloseKey(hMicrosoftOutlook);      
             }
                
                // If FGetComponentPath returns FALSE or if
                // it returned nothing, or if we never found an
                // address of FGetComponentPath, then
                // just default to the system directory
             if (!bRet || szMAPIDir[0] == '\0')
             {
                hRes = StringCchPrintfA(
                   szMAPIDir, cchMAPIDir,"%s", szSystemDir);
             }
             
             if (szMAPIDir[0] != _T('\0'))
             {
                hRes = StringCchPrintfA(
                   szMAPIDir, cchMAPIDir, "%s\\%s", szMAPIDir, "MAPISVC.INF");
             }
             
             if (hmodMapi32) FreeLibrary(hmodMapi32);
             if (hmodStub) FreeLibrary(hmodStub);
          }
       }   
    }
  • SGriffin's MAPI Internals

    New MAPI Goodness

    Posted over 6 years ago
    by Stephen Griffin - MSFT
    • 0 Comments

    Updates to the downloads of CDO and MAPI/CDO are now available. Here are the links:

    CDO 1.21: (download of CDO for use with Outlook 2007)

    http://www.microsoft.com/downloads/details.aspx?familyid=2714320D-C997-4DE1-986F-24F081725D36&displaylang=en

    MAPI/CDO download: (standalone package of MAPI and CDO for use on Exchange 2007 servers and other machines that don't already have MAPI)

    http://www.microsoft.com/downloads/details.aspx?familyid=E17E7F31-079A-43A9-BFF2-0A110307611E&displaylang=en

     

    And some details on the updates:

    CDO 1.21:

    • Fixed installer not to install with any version of Outlook prior to Outlook 2007
    • Many, MANY timezone fixes, including support for the upcoming 2007 DST changes here in the States
    • Fixed a heap corruption issue

    MAPI/CDO download:

    • Improved support for public folder free Exchange 2007 environments (I have a blog coming on this).
    • Registry keys that indicate MAPI is installed weren't being set properly.
    • Since this ships the same version of CDO.dll as the CDO download, it includes those fixes as well.

     

    Version Numbers:

    Both packages include version 6.5.7888.0 of their respective binaries.

    As usual, any feedback you have on these is appreciated. I'll pass it over to the appropriate devs.

Page 1 of 1 (2 items)
  • © 2013 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy & Cookies
  • Report Abuse
  • 5.6.426.415