#include <io.h>
#pragma comment(lib, "Version.lib")
char* getLocalProgramVersion()
{
char FileName[MAX_PATH] = {0};
::GetModuleFileName(NULL, FileName, sizeof(FileName) - 1);
string asVer = "";
VS_FIXEDFILEINFO *pVsInfo;
unsigned int iFileInfoSize = sizeof(VS_FIXEDFILEINFO);
int iVerInfoSize = GetFileVersionInfoSize(FileName, NULL);
if(iVerInfoSize != 0){
char *pBuf = NULL;
while(!pBuf){
pBuf = new char[iVerInfoSize];
}
if(GetFileVersionInfo(FileName, 0, iVerInfoSize, pBuf)){
if(VerQueryValue(pBuf, "\\", (void **)&pVsInfo, &iFileInfoSize)){
sprintf(pBuf, "%d.%d.%d.%d", HIWORD(pVsInfo->dwFileVersionMS), LOWORD(pVsInfo->dwFileVersionMS), HIWORD(pVsInfo->dwFileVersionLS), LOWORD(pVsInfo->dwFileVersionLS));
asVer = pBuf;
}
}
delete pBuf;
}
return asVer;
}
C++获取文件版本信息
最新推荐文章于 2024-08-12 11:24:11 发布