Microsoft KB Archive/229700

= How to locate the correct path to the Mapisvc.inf file in Microsoft Outlook =

Article ID: 229700

Article Last Modified on 8/25/2005

-

APPLIES TO


 * Microsoft Office Outlook 2003
 * Microsoft Outlook 2002 Standard Edition
 * Microsoft Outlook 2000 Standard Edition
 * Microsoft Messaging Application Programming Interface

-



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); }   } }

Additional query words: Outlook 2000 OL2K OL2000 Outlook2000 MAPISVC.INF IMsgServiceAdmin kbGrpMsg kbMsg kbMAPI kbMAPI100 kbOutlook97 kbOutlook98

Keywords: kbhowto kbmsg kbfaq KB229700

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.