DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 229700 - Last Review: August 25, 2005 - Revision: 5.4

This article was previously published under Q229700

SUMMARY

Microsoft Outlook exposes the FGetComponentPath function in the Mapistub.dll file that helps you find the path to the Mapisvc.inf file. This article describes how to find the path to the Mapisvc.Inf file by using the code sample in the "More Information" section.

Before Microsoft Outlook 2000, the Mapisvc.inf file was always installed under the system directory, as returned by the Win32 API GetSystemDirectory function.

MORE INFORMATION

Note The following code sample is backward compatible with all previous versions of Outlook. The following code sample finds the path to the Mapisvc.inf file whether the Mapisvc.inf file exists under the system directory or not.
typedef BOOL (STDAPICALLTYPE FGETCOMPONENTPATH)
(LPSTR szComponent,
 LPSTR szQualifier,
 LPSTR szDllPath,
 DWORD cchBufferSize,
 BOOL fInstall);
typedef FGETCOMPONENTPATH FAR * LPFGETCOMPONENTPATH;    

/////////////////////////////////////////////////////////////////////////////// 
// Function name    : InitMAPIDir
// Description      : For Outlook 2000 compliance. 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 cchINIFileName - size of szMAPIDir
void InitMAPIDir(LPSTR szINIFileName, ULONG cchINIFileName)
{
    UINT uiRet = 0;
    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)
    {
        HRESULT hRes = S_OK;
        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");
                    }
                }
            }

            BOOL bRet = FALSE;

            if(pfnFGetComponentPath)
            {
                // Now that we have the address of FGetComponentPath
                // Let's call it with the GUID for mapisvc.inf
                bRet = pfnFGetComponentPath(
                    "{473FF9A0-D659-11D1-A4B2-006008AF820E}",
                    NULL, szINIFileName, cchINIFileName, TRUE); 
            }

            // 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 || szINIFileName[0] == '\0')
            {
                hRes = StringCchPrintfA(szINIFileName, cchINIFileName,
                    "%s\\%s", szSystemDir, "mapisvc.inf");
            }

            if(hmodMapi32)
                FreeLibrary(hmodMapi32);

            if(hmodStub)
                FreeLibrary(hmodStub);
        }
    }
}

APPLIES TO
  • Microsoft Office Outlook 2003
  • Microsoft Outlook 2002 Standard Edition
  • Microsoft Outlook 2000 Standard Edition
  • Microsoft Messaging Application Programming Interface
Keywords: 
kbfaq kbhowto kbmsg KB229700
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support