获取exe的版本号

CString GetFileVersion(const CString& sTargetFileName)
{
	DWORD nInfoSize = 0, dwHandle = 0;
	nInfoSize = GetFileVersionInfoSize(sTargetFileName, &dwHandle);
	if (nInfoSize == 0) 
	{
		return _T("");
	}

	char* pInfoBuf = new char[nInfoSize];
	GetFileVersionInfo(sTargetFileName, 0, nInfoSize, pInfoBuf);

	struct LANGANDCODEPAGE  {
		WORD wLanguage;
		WORD wCodePage;
	}* pTranslate;

	UINT  cbTranslate = 0;
	VerQueryValue(pInfoBuf, TEXT("\\VarFileInfo\\Translation"), (LPVOID*)&pTranslate, &cbTranslate);


        CString version;
	// Read the file description for each language and code page.
	for( int i = 0; i < (cbTranslate/sizeof(struct LANGANDCODEPAGE)); i++ )
	{
		WCHAR SubBlock[256] = {0};
		wsprintf( SubBlock,
			TEXT("\\StringFileInfo\\%04x%04x\\FileVersion"),
			pTranslate[i].wLanguage,
			pTranslate[i].wCodePage);

		WCHAR* pVersion = NULL;
		UINT nBytes = 0;
		VerQueryValue(pInfoBuf, SubBlock, (LPVOID*)&pVersion, &nBytes);
		version = pVersion;
		break;
	}

	delete pInfoBuf;

	return version;
}


发布了21 篇原创文章 · 获赞 1 · 访问量 3万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览