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