QT用API获得文件的版本信息

本文介绍了如何在Qt环境中利用Windows API(GetFileVersionInfoSize, GetFileVersionInfo, VerQueryValue)来获取EXE文件的版本信息,同时提及了与Visual Studio 2012在Windows平台上的相关应用。" 117881030,10552041,Discuz头像上传:从Flash到HTML5的转换教程,"['discuz', 'HTML5上传', '论坛管理', 'PHP']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Qt:

#include<windows.h>

#include<winver.h>

///引入Version.lib库

QString InfomationCollect::GetFileVertion( QString fullName )
{
  
  
// 必须要用,不然无法获取到exe的版本信息
<span style="white-space:pre">	</span>#pragma comment(lib, "Version")
DWORD dwLen = 0;
char* lpData=NULL;

BOOL bSuccess = FALSE;
QString fileInfomation;
//获得文件基础信息
//--------------------------------------------------------
dwLen = GetFileVersionInfoSize(fullName.toStdWString().c_str(), 0);
if (0 == dwLen)
{
//qDebug()<<"Get file verstion error!";
return"";
}
lpData =new char [dwLen+1];

bSuccess = GetFileVersionInfo(fullName.toStdWString().c_str(), 0, dwLen, lpData);
if (!bSuccess)
{
//qDebug()<<"Get file verstion error!";
delete lpData;
return"";
}

LPVOID lpBuffer = NULL;
UINT uLen = 0;

//获得语言和代码页(language and code page)
//---------------------------------------------------
bSuccess = VerQueryValue(lpData,
(TEXT("\VarFileInfo\Translation")),
&lpBuffer,
&uLen);
QString strTranslation,str1,str2;
unsigned short int *p =(unsigned short int *)lpBuffer;
str1.setNum(*p,16);
str1="000"+ str1;
strTranslation+= str1.mid(str1.size()-4,4);
str2.setNum(*(++p),16);
str2="000"+ str2;
strTranslation+= str2.mid(str2.size()-4,4);
//获得文件版
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值