mfc获取exe的版本信息


CString GetFileVersion(const CString& sTargetFileName)
{
DWORD nInfoSize = 0, dwHandle = 0;
nInfoSize = GetFileVersionInfoSize(sTargetFileName, &dwHandle);
if (nInfoSize == 0)
{
return _T("");
}

char* pInfoBuf = new char[nInfoSize];
GetFileVersionInfo(sTargetFileName, 0, nInfoSize, pInfoBuf);

struct LANGANDCODEPAGE {
WORD wLanguage;
WORD wCodePage;
}*pTranslate;

UINT cbTranslate = 0;
VerQueryValue(pInfoBuf, TEXT("\\VarFileInfo\\Translation"), (LPVOID*)&pTranslate, &cbTranslate);


CString version;
// Read the file description for each language and code page.
for (int i = 0; i < (cbTranslate / sizeof(struct LANGANDCODEPAGE)); i++)
{
WCHAR SubBlock[256] = { 0 };
wsprintf(SubBlock,
TEXT("\\StringFileInfo\\%04x%04x\\FileVersion"),
pTranslate[i].wLanguage,
pTranslate[i].wCodePage);

WCHAR* pVersion = NULL;
UINT nBytes = 0;
VerQueryValue(pInfoBuf, SubBlock, (LPVOID*)&pVersion, &nBytes);
version = pVersion;
break;
}

delete pInfoBuf;

return version;

}

void CtestmfcversionDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
CString stdstr("C:\\Program Files (x86)\\VMware\\VMware Workstation\\vmware.exe");
GetFileVersion(stdstr);
CDialogEx::OnOK();
}

posted on 2019-04-16 11:23  lydstory  阅读(680)  评论(0编辑  收藏  举报

导航