﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>学习日记 &#187; version</title>
	<atom:link href="https://www.softwareace.cn/?feed=rss2&#038;tag=version" rel="self" type="application/rss+xml" />
	<link>https://www.softwareace.cn</link>
	<description>时刻想着为自己的产品多做一些对他好的事情</description>
	<lastBuildDate>Fri, 20 Mar 2026 06:58:28 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>QT用API获得文件的版本信息</title>
		<link>https://www.softwareace.cn/?p=88</link>
		<comments>https://www.softwareace.cn/?p=88#comments</comments>
		<pubDate>Fri, 18 Jan 2013 06:22:23 +0000</pubDate>
		<dc:creator><![CDATA[littlesu]]></dc:creator>
				<category><![CDATA[Qt Gui]]></category>
		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=88</guid>
		<description><![CDATA[[crayon-69fc184b152b2837048474/]]]></description>
				<content:encoded><![CDATA[<p></p><pre class="crayon-plain-tag">#include&amp;lt;windows.h&amp;gt;

#include&amp;lt;winver.h&amp;gt;

///引入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()&amp;lt;&amp;lt;&amp;quot;Get file verstion error! &amp;quot;;
return &amp;quot;&amp;quot;;
}
lpData =new char [dwLen+1];

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

LPVOID lpBuffer = NULL;
UINT uLen = 0;

//获得语言和代码页(language and code page)
//---------------------------------------------------
bSuccess = VerQueryValue(lpData,
(TEXT(&amp;quot;\VarFileInfo\Translation&amp;quot;)),
&amp;amp;lpBuffer,
&amp;amp;uLen);
QString strTranslation,str1,str2;
unsigned short int *p =(unsigned short int *)lpBuffer;
str1.setNum(*p,16);
str1=&amp;quot;000&amp;quot; + str1;
strTranslation+= str1.mid(str1.size()-4,4);
str2.setNum(*(++p),16);
str2=&amp;quot;000&amp;quot; + str2;
strTranslation+= str2.mid(str2.size()-4,4);
//获得文件版本信息
//-----------------------------------------------------
QString code = &amp;quot;\StringFileInfo\&amp;quot;+ strTranslation +&amp;quot;\FileVersion&amp;quot;;
bSuccess = VerQueryValue(lpData,
(code.toStdWString().c_str()),
&amp;amp;lpBuffer,
&amp;amp;uLen);
if (!bSuccess)
{
//qDebug()&amp;lt;&amp;lt;&amp;quot;Get file verstion error! &amp;quot;;
delete lpData;
return &amp;quot;&amp;quot;;
}
fileInfomation += QString::fromUtf16((const unsigned short int *)lpBuffer);
//获得文件的描述
//---------------------------------------------------------
/*code = &amp;quot;\StringFileInfo\&amp;quot;+ strTranslation +&amp;quot;\FileDescription&amp;quot;;
bSuccess = VerQueryValue(lpData,
(code.toStdWString().c_str()),
&amp;amp;lpBuffer,
&amp;amp;uLen);
if (!bSuccess)
{
qDebug()&amp;lt;&amp;lt;&amp;quot;Get file verstion error! &amp;quot;;
delete lpData;
return &amp;quot;&amp;quot;;
}
fileInfomation +=&amp;quot;^&amp;quot;;
fileInfomation += QString::fromUtf16((const unsigned short int *)lpBuffer);*/
delete [] lpData;//此处不需要释放
return fileInfomation;
}

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

//VC版本

char* szFileName = &amp;ldquo;C:\EnochShen.exe&amp;rdquo;;
DWORD dwSize = GetFileVersionInfoSize(szFileName,NULL);
LPVOID pBlock = malloc(dwSize);
GetFileVersionInfo(szFileName,0,dwSize,pBlock);

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

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

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

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

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

//原始文件名
strSubBlock.Format(&amp;ldquo;\StringFileInfo\%s\OriginalFileName&amp;rdquo;,strTranslation);
VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&amp;amp;pVerValue,&amp;amp;nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(&amp;ldquo;原始文件名: %s&amp;rdquo;,pVerValue);
AfxMessageBox(strTemp);

//产品名称
strSubBlock.Format(&amp;ldquo;\StringFileInfo\%s\ProductName&amp;rdquo;,strTranslation);
VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&amp;amp;pVerValue,&amp;amp;nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(&amp;ldquo;产品名称: %s&amp;rdquo;,pVerValue);
AfxMessageBox(strTemp);

//产品版本
strSubBlock.Format(&amp;ldquo;\StringFileInfo\%s\ProductVersion&amp;rdquo;,strTranslation);
VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&amp;amp;pVerValue,&amp;amp;nSize);
strSubBlock.ReleaseBuffer();
strTemp.Format(&amp;ldquo;产品版本: %s&amp;rdquo;,pVerValue);
AfxMessageBox(strTemp);

free(pBlock);</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=88</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
