HRESULT CAboutDlg::GetVersion(__out CString& strVersion)
{
strVersion = _T("版本未知");
TCHAR szFileName[MAX_PATH] = {0};
GetModuleFileName(NULL, szFileName, MAX_PATH);
DWORD dwSize = GetFileVersionInfoSize(szFileName, NULL);
if(dwSize == 0)
return E_FAIL;
TCHAR* pszVersionInfo = new TCHAR[dwSize];
ZeroMemory(pszVersionInfo, dwSize);
BOOL bRet = GetFileVersionInfo(szFileName, 0, dwSize, pszVersionInfo);
if(!bRet)
{
delete [] pszVersionInfo;
return E_FAIL;
}
VS_FIXEDFILEINFO *pFileInfo = NULL;
UINT pLenFileInfo = 0;
bRet = VerQueryValue(pszVersionInfo, _T("\\"), (LPVOID*)&pFileInfo, &pLenFileInfo);
if(!bRet)
{
delete [] pszVersionInfo;
return E_FAIL;
}
strVersion.Format(_T("%d.%d.%d.%d"),
HIWORD(pFileInfo->dwFileVersionMS),
LOWORD(pFileInfo->dwFileVersionMS),
HIWORD(pFileInfo->dwFileVersionLS),
LOWORD(pFileInfo->dwFileVersionLS));
delete [] pszVersionInfo;
return S_OK;
}
从exe中读取版本信息
最新推荐文章于 2024-08-12 11:24:11 发布