获取EXE文件版本信息(版本格式:xx.xx.xx.xx)

BOOL GetVersion(LPTSTR lpszVersion, size_t nLength, LPCTSTR lpszExecute)
{
	BOOL bRet = FALSE;

	TCHAR* pVersion = NULL;

	do
	{
		if ((NULL == lpszVersion) || (nLength <= 0) || (NULL == lpszExecute)) { break; }
		
		DWORD dwSize = GetFileVersionInfoSize(lpszExecute, NULL);
		if (0 == dwSize) { break; }

		pVersion = new TCHAR[dwSize + 1];
		if (NULL == pVersion) { break; }

		_ASSERT(NULL != pVersion);
		memset(pVersion, 0, sizeof(TCHAR) * (dwSize + 1));

		if (!GetFileVersionInfo(lpszExecute, 0, dwSize, pVersion)) { break; }

		VS_FIXEDFILEINFO * pInfo = NULL;
		unsigned int nInfoLen = 0;

		if (!VerQueryValue(pVersion, TEXT("\\"), (void**)&pInfo, &nInfoLen)) { break; }

		StringCchPrintf(lpszVersion, nLength, TEXT("%d.%d.%d.%d"), HIWORD(pInfo->dwFileVersionMS), LOWORD(pInfo->dwFileVersionMS), HIWORD(pInfo->dwFileVersionLS), LOWORD(pInfo->dwFileVersionLS));

		// Completed
		bRet = TRUE;
	} while (0);
	
	if (NULL != pVersion) { delete[] pVersion; pVersion = NULL; }

	return bRet;
}


发布了74 篇原创文章 · 获赞 90 · 访问量 38万+
展开阅读全文

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

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

分享到微信朋友圈

×

扫一扫,手机浏览