HOWTO: Find the Correct Path to MAPISVC.INF Under Outlook 2000

ID: Q229700


The information in this article applies to:


SUMMARY

Outlook exposes a function, FGetComponentPath(), in the Mapistub.dll file that helps us find the path to the Mapisvc.inf file. This article contains a code sample demonstrating how to do this.

Prior to Outlook 2000, the Mapisvc.inf file was always installed under the system directory (as returned by the Win32 API GetSystemDirectory()).

Note that the following code sample is also backward compatible with all prior versions of Outlook. It will find the path to the Mapisvc.inf file whether it exists under the system directory or not.


MORE INFORMATION


typedef BOOL (STDAPICALLTYPE FGETCOMPONENTPATH)
	(LPSTR szComponent,
	LPSTR szQualifier,
	LPSTR szDllPath,
	DWORD cchBufferSize,
	BOOL fInstall);
typedef FGETCOMPONENTPATH FAR * LPFGETCOMPONENTPATH;

static TCHAR s_szMSIApplicationLCID[] =
	"Microsoft\\Office\\9.0\\Outlook\0LastUILanguage\0";	
static TCHAR s_szMSIOfficeLCID[] =
	"Microsoft\\Office\\9.0\\Common\\LanguageResources\0UILanguage\0InstallLanguage\0";		

/////////////////////////////////////////////////////////////////////////////// 
// 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.
void InitMAPIDir(LPTSTR szINIFileName)
{
	// Get the mapisvc.inf filename.  
	// The MAPISVC.INF file can live in the system directory.
	// and/or "\Program Files\Common Files\SYSTEM\Mapi"
	UINT				cchT;
	static const TCHAR	szMapiSvcInf[] = TEXT("\\mapisvc.inf");
	LPFGETCOMPONENTPATH pfnFGetComponentPath;

	// Char array for private mapisvc.inf.
	char	szPrivateMAPIDir[MAX_PATH] = {0};

	HINSTANCE hinstStub = NULL;

	// Get Windows System Directory.
	if(!(cchT = GetSystemDirectory(szINIFileName, MAX_PATH)))
		goto Done; //return MAPI_E_CALL_FAILED;

	if(szINIFileName[cchT - 1] == '\\')
	{
		szINIFileName[cchT - 1] = 0;
	}
	// Append Filename to the Path.
	lstrcat(szINIFileName, szMapiSvcInf);

	// Call common code in mapistub.dll.
	hinstStub = LoadLibrary("mapistub.dll");
	if (!hinstStub)
	{
		// Try stub mapi32.dll if mapistub.dll missing.
		hinstStub = LoadLibrary("mapi32.dll");
		if (!hinstStub)
			goto Done;
	}

	if(hinstStub)
	{
		pfnFGetComponentPath = (LPFGETCOMPONENTPATH)GetProcAddress(hinstStub, "FGetComponentPath");

		if (!pfnFGetComponentPath)
			goto Done;

		if ((pfnFGetComponentPath("{FF1D0740-D227-11D1-A4B0-006008AF820E}",
				s_szMSIApplicationLCID, szPrivateMAPIDir, MAX_PATH, TRUE) ||
			pfnFGetComponentPath("{FF1D0740-D227-11D1-A4B0-006008AF820E}",
				s_szMSIOfficeLCID, szPrivateMAPIDir, MAX_PATH, TRUE) ||
			pfnFGetComponentPath("{FF1D0740-D227-11D1-A4B0-006008AF820E}",
				NULL, szPrivateMAPIDir, MAX_PATH, TRUE)) &&
				szPrivateMAPIDir[0] != '\0')
		{
			szPrivateMAPIDir[lstrlen(szPrivateMAPIDir) - 13] = 0;	// Strip "\msmapi32.dll"
		}
		else
		{
			szPrivateMAPIDir[0] = '\0';	// Terminate String at pos 0.
		}

		// Write private mapisvc.inf in szINIFileName if it exists
		if (*szPrivateMAPIDir)
		{
			lstrcpy(szINIFileName, szPrivateMAPIDir);
			lstrcat(szINIFileName, szMapiSvcInf);
		}
	}

Done:
	TRACE1("mapisvc file: '%s'", szINIFileName);

	if (hinstStub) FreeLibrary(hinstStub);
}
 

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


Keywords          : kbMAPI kbMsg kbOutlook97 kbOutlook98 kbMAPI100 kbGrpMsg 
Version           : WINDOWS:1.0,2000,97,98
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: August 8, 1999