// Test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <Windows.h>
#include <tchar.h>
#include <string>
#include <iostream>
#pragma comment(lib,"version.lib")
using namespace std;
string GetFileVersion(PCSTR filename)
{
string asVer = "";
VS_FIXEDFILEINFO *pVsInfo;
unsigned int iFileInfoSize = sizeof(VS_FIXEDFILEINFO);
int iVerInfoSize = GetFileVersionInfoSizeA(filename, NULL);
if(iVerInfoSize != 0)
{
char *pBuf = NULL;
while(!pBuf)
{
pBuf = new char[iVerInfoSize];
}
if(GetFileVersionInfoA(filename, 0, iVerInfoSize, pBuf))
{
if(VerQueryValueA(pBuf, "\\", (void **)&pVsInfo, &iFileInfoSize))
{
sprintf(pBuf, "%d.%d.%d.%d", HIWORD(pVsInfo->dwFileVersionMS), LOWORD(pVsInfo->dwFileVersionMS), HIWORD(pVsInfo->dwFileVersionLS), LOWORD(pVsInfo->dwFileVersionLS));
asVer = pBuf;
}
}
delete pBuf;
}
return asVer;
}
int _tmain(int argc, _TCHAR* argv[])
{
string strFilePath = "C:\\Users\\jhon am\\Desktop\\Backupper.exe";
string version = GetFileVersion(strFilePath.c_str());
getchar();
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)