vc获取进程版本号

#param comment(lib, "version.lib")

CString &CMonitorManagerDlg::GetApplicationVersion(CString &strVersion)
{
char cPath[200];
DWORD dwHandle,InfoSize;

::GetModuleFileName(NULL,cPath,sizeof(cPath)); //首先获得版本信息资源的长度
InfoSize = GetFileVersionInfoSize(cPath,&dwHandle); //将版本信息资源读入缓冲区
if(InfoSize==0)
return strVersion;

char *InfoBuf = new char[InfoSize];
GetFileVersionInfo(cPath,0,InfoSize,InfoBuf); //获得生成文件使用的代码页及文件版本

unsigned int cbTranslate = 0;
struct LANGANDCODEPAGE {
WORD wLanguage;
WORD wCodePage;
} *lpTranslate;

VerQueryValue(InfoBuf, TEXT("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &cbTranslate);

// Read the file description for each language and code page.
for( size_t i=0; i < (cbTranslate/sizeof(struct LANGANDCODEPAGE)); i++ )
{
char SubBlock[200];

wsprintf( SubBlock,
TEXT("\\StringFileInfo\\%04x%04x\\FileVersion"),
lpTranslate[i].wLanguage,
lpTranslate[i].wCodePage);

void *lpBuffer=NULL;
unsigned int dwBytes=0;
VerQueryValue(InfoBuf,
SubBlock,
&lpBuffer,
&dwBytes);

strVersion += (char *)lpBuffer;
}

if (InfoBuf)
{
delete []InfoBuf;
InfoBuf = NULL;
}

return strVersion;
}

vc获取进程版本号

上一篇:Linux中error while loading shared libraries错误解决办法


下一篇:Linux学习111 基于LVS实现4层负载均衡模式和场景应用