VS2015(MFC) 抓取+顯示版本資訊
VS2015(MFC) 抓取+顯示版本資訊
資料來源: http://lkqlinsblog.blogspot.tw/2017/11/windows-mfc-get-appliation-version.html
CString ClassName::getAppVersion()//必須引用version.lib
{
int major, minor, build, revision;
DWORD verBufferSize;
char verBuffer[2048];
CString version;
TCHAR AppName[MAX_PATH];
GetModuleFileName(NULL, AppName, MAX_PATH);
// Get the size of the version info block in the file
verBufferSize = GetFileVersionInfoSize(AppName, NULL);
if (verBufferSize > 0 && verBufferSize <= sizeof(verBuffer))
{
// get the version block from the file
if (TRUE == GetFileVersionInfo(AppName, NULL, verBufferSize, verBuffer))
{
UINT length;
VS_FIXEDFILEINFO *verInfo = NULL;
// Query the version information for neutral language
if (TRUE == VerQueryValue(
verBuffer,
_T(“\\”),
reinterpret_cast<LPVOID*>(&verInfo),
&length))
{
// Pull the version values.
major = HIWORD(verInfo->dwProductVersionMS);
minor = LOWORD(verInfo->dwProductVersionMS);
build = HIWORD(verInfo->dwProductVersionLS);
revision = LOWORD(verInfo->dwProductVersionLS);
}
}
}
version.Format(_T(“V %d.%d.%d.%d”), major, minor, build, revision);
return version;
}