Windows程序读取自身程序版本信息
自己写某产品时的代码,虽然网上有一堆一堆,但是这个是自己调试过的,自己留着给自己看
VOID GetInstanceVersion()
{
BOOL version_get = FALSE;
DWORD dwVersionInfoSize;
TCHAR szFile[255];
memset(szFile,0x00,sizeof(szFile));
GetModuleFileName(NULL,szFile,255);
dwVersionInfoSize = ::GetFileVersionInfoSize(szFile, NULL);
if (0 == dwVersionInfoSize)
{
//return false;
version_get = FALSE;
}
char* pVersionInfo = new char[dwVersionInfoSize];
memset(pVersionInfo,0x00,sizeof(pVersionInfo));
if (0 == GetFileVersionInfo(szFile, NULL, dwVersionInfoSize, pVersionInfo))
{
delete[] pVersionInfo;
}
VS_FIXEDFILEINFO* pVersion = NULL;
unsigned int nLen;
if(FALSE == ::VerQueryValue(pVersionInfo, _T("\\"), (void**)&pVersion, &nLen))
{
delete[] pVersionInfo;
//return false;
version_get = FALSE;
}
int nFileVersionMS = pVersion->dwFileVersionMS;
int nFileVersionLS = pVersion->dwFileVersionLS;
valStr.Format(_T("%d.%d.%d.%d"), (pVersion->dwFileVersionMS >> 16) & 0xFF, (pVersion->dwFileVersionMS) & 0xFF, (pVersion->dwFileVersionLS >> 16) & 0xFF, (pVersion->dwFileVersionLS));
delete[] pVersionInfo;
}