Locating MAPI directory using FGetComponentPath
Codes below quoted from
URL
By Sam Charchian
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"; // STRING_OK
static TCHAR s_szMSIOfficeLCID[] =
"Microsoft\\Office\\9.0\\Common\\LanguageResources\0UILanguage\0InstallLangu
age\0"; // STRING_OK
////////////////////////////////////////////////////////////////////////////
///
// Function name : CSVCFile::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 CSVCFile::InitMAPIDir(LPTSTR szMAPIDir)
{
HINSTANCE hinstStub = NULL;
// 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;
}
LPFGETCOMPONENTPATH pfnFGetComponentPath;
pfnFGetComponentPath = (LPFGETCOMPONENTPATH)
GetProcAddress(hinstStub, "FGetComponentPath");
if (!pfnFGetComponentPath)
goto Done;
if ((pfnFGetComponentPath("{FF1D0740-D227-11D1-A4B0-006008AF820E}",
s_szMSIApplicationLCID, szMAPIDir, MAX_PATH, TRUE)
||
pfnFGetComponentPath("{FF1D0740-D227-11D1-A4B0-006008AF820E}",
s_szMSIOfficeLCID, szMAPIDir, MAX_PATH, TRUE) ||
pfnFGetComponentPath("{FF1D0740-D227-11D1-A4B0-006008AF820E}",
NULL, szMAPIDir, MAX_PATH, TRUE)) &&
szMAPIDir[0] != '\0')
{
szMAPIDir[lstrlen(szMAPIDir) - 13] = 0; // Strip
"\msmapi32.dll"
}
else
{
szMAPIDir[0] = '\0'; // Terminate String at pos 0.
}
Done:
if (hinstStub)
FreeLibrary(hinstStub);
}
Another reference available in
http://support.microsoft.com/kb/229700
and
(In Delphi by Dmitry Streblechenko)
URL
URL
By Sam Charchian
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"; // STRING_OK
static TCHAR s_szMSIOfficeLCID[] =
"Microsoft\\Office\\9.0\\Common\\LanguageResources\0UILanguage\0InstallLangu
age\0"; // STRING_OK
////////////////////////////////////////////////////////////////////////////
///
// Function name : CSVCFile::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 CSVCFile::InitMAPIDir(LPTSTR szMAPIDir)
{
HINSTANCE hinstStub = NULL;
// 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;
}
LPFGETCOMPONENTPATH pfnFGetComponentPath;
pfnFGetComponentPath = (LPFGETCOMPONENTPATH)
GetProcAddress(hinstStub, "FGetComponentPath");
if (!pfnFGetComponentPath)
goto Done;
if ((pfnFGetComponentPath("{FF1D0740-D227-11D1-A4B0-006008AF820E}",
s_szMSIApplicationLCID, szMAPIDir, MAX_PATH, TRUE)
||
pfnFGetComponentPath("{FF1D0740-D227-11D1-A4B0-006008AF820E}",
s_szMSIOfficeLCID, szMAPIDir, MAX_PATH, TRUE) ||
pfnFGetComponentPath("{FF1D0740-D227-11D1-A4B0-006008AF820E}",
NULL, szMAPIDir, MAX_PATH, TRUE)) &&
szMAPIDir[0] != '\0')
{
szMAPIDir[lstrlen(szMAPIDir) - 13] = 0; // Strip
"\msmapi32.dll"
}
else
{
szMAPIDir[0] = '\0'; // Terminate String at pos 0.
}
Done:
if (hinstStub)
FreeLibrary(hinstStub);
}
Another reference available in
http://support.microsoft.com/kb/229700
and
(In Delphi by Dmitry Streblechenko)
URL
Comments