#include <Msi.h>
#pragma comment(lib, "Msi.lib")
static HRESULT GetComponentPath(LPCTSTR szShortcutTarget, LPTSTR lpPathBuf, DWORD* pcchBuf)
{
if ((lpPathBuf == NULL) || (pcchBuf == NULL))
{
return E_POINTER;
}
UINT nr = ERROR_SUCCESS;
TCHAR szProductCode[39];
TCHAR szFeatureId[MAX_FEATURE_CHARS + 1];
TCHAR szComponentCode[39];
nr = ::MsiGetShortcutTarget(szShortcutTarget, szProductCode, szFeatureId, szComponentCode);
if (nr != ERROR_SUCCESS)
{
return E_FAIL;
}
nr = ::MsiGetComponentPath(szProductCode, szComponentCode, lpPathBuf, pcchBuf);
if (nr != INSTALLSTATE_LOCAL)
{
// 戻り値が、INSTALLSTATE_LOCALの場合、ファイル名が取得できる
// その他の値の場合は、未検証。。
return E_FAIL;
}
return S_OK;
}