c++ 获取软件版本信息

#include<string>
#include<iostream>
#include<Windows.h>
#include<io.h>
#include<tchar.h>
using namespace std;

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


std::string GetSoftVersion(const char* exepath)
{
	std::string r = "";
	if (!exepath)
		return r;
	if (_access(exepath, 0) != 0)
		return r;
	UINT sz = GetFileVersionInfoSize(exepath, 0);
	if (sz != 0) {
		r.resize(sz, 0);
		char *pBuf = NULL;
		pBuf = new char[sz];
		VS_FIXEDFILEINFO *pVsInfo;
		if (GetFileVersionInfo(exepath, 0, sz, pBuf)) {
			if (VerQueryValue(pBuf, "\\", (void **)&pVsInfo, &sz)) {
				sprintf(pBuf, "%d.%d.%d.%d", HIWORD(pVsInfo->dwFileVersionMS), LOWORD(pVsInfo->dwFileVersionMS), HIWORD(pVsInfo->dwFileVersionLS), LOWORD(pVsInfo->dwFileVersionLS));
				r = pBuf;
			}
		}
		delete pBuf;
	}
	return r;
}

int main()
{

	std::string info= GetSoftVersion("C:\\Program Files (x86)\\Tencent\\QQ\\Bin\\QQ.exe");
	std::cout << info << std::endl;
	getchar();
    return 0;
}




版权声明:本文为xzpblog原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。