设为首页 加入收藏

TOP

QT用API获得文件的版本信息(一)
2014-11-24 08:42:15 来源: 作者: 【 】 浏览:0
Tags:API 获得 文件 版本 信息

#include


#include


///引入Version.lib库


QString InfomationCollect::GetFileVertion( QString fullName )
{
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);
//获得文件版本信息
//-----------------------------------------------------
QString code = "\\StringFileInfo\\"+ strTranslation +"\\FileVersion";
bSuccess = VerQueryValue(lpData,
(code.toStdWString().c_str()),
&lpBuffer,
&uLen);
if (!bSuccess)
{
//qDebug()<<"Get file verstion error! ";
delete lpData;
return "";
}
fileInfomation += QString::fromUtf16((const unsigned short int *)lpBuffer);
//获得文件的描述
//---------------------------------------------------------
/*code = "\\StringFileInfo\\"+ strTranslation +"\\FileDescription";
bSuccess = VerQueryValue(lpData,
(code.toStdWString().c_str()),
&lpBuffer,
&uLen);
if (!bSuccess)
{
qDebug()<<"Get file verstion error! ";
delete lpData;
return "";
}
fileInfomation +="^";
fileInfomation += QString::fromUtf16((const unsigned short int *)lpBuffer);*/
delete [] lpData;//此处不需要释放
return fileInfomation;
}


//==================================================


//VC版本


char* szFileName = “C:\\EnochShen.exe”;
DWORD dwSize = GetFileVersionInfoSize(szFileName,NULL);
LPVOID pBlock = malloc(dwSize);
GetFileVersionInfo(szFileName,0,dwSize,pBlock);


char* pVerValue = NULL;
UINT nSize = 0;
VerQueryValue(pBlock,TEXT(“\\VarFileInfo\\Translation”),
(LPVOID*)&pVerValue,&nSize);


CString strSubBlock,strTranslation,strTemp;
strTemp.Format(“000%x”,*((unsigned short int *)pVerValue));
strTranslation = strTemp.Right(4);
strTemp.Format(“000%x”,*((unsigned short int *)&pVerValue[2]));
strTranslation += strTemp.Right(4);
//080404b0为中文,040904E4为英文


//文件描述
strSubBlock.Format(“\\StringFileInfo\\%s\\FileDescription”,strTranslation);
VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(“文件描述: %s”,pVerValue);
AfxMessageBox(strTemp);


//内部名称
strSubBlock.Format(“\\StringFileInfo\\%s\\InternalName”,strTranslation);
VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(“文件描述: %s”,pVerValue);
AfxMessageBox(strTemp);


//合法版权
strSubBlock.Format(“\\StringFileInfo\\%s\\LegalTradeMarks”,strTranslation);
VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(“合法版权: %s”,pVerValue);
AfxMessageBox(strTemp);


//原始文件名
strSubBlock.Format(“\\StringFi

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Qt creator 添加qmake rebuild出错 下一篇Java简单实现webservice接口

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·有没有哪些高效的c++ (2025-12-27 08:20:57)
·Socket 编程时 Accep (2025-12-27 08:20:54)
·计算机网络知识点总 (2025-12-27 08:20:52)
·一篇说人话的文章, (2025-12-27 07:50:09)
·Python Web框架哪家 (2025-12-27 07:50:06)