#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;
}