高手接招,菜鸟进来看看,有个好函数给你。关于文件版本信息!(50分)

  • 主题发起人 主题发起人 Kingron
  • 开始时间 开始时间
K

Kingron

Unregistered / Unconfirmed
GUEST, unregistred user!
这个函数很有用的!用于取得文件的版本信息!(我都调试通过了D5 SP1+Win200 SP1)但是有一个地方我无法解决!<br>请注意那个UserDefineValue,必须传入一个字符串,对于用户自定义的来说,这个是不确定的。<br>我的问题是,如何知道用户自定义了那些 字符串版本 信息?<br>type<br>&nbsp; TFileInfo = packed record<br>&nbsp; &nbsp; CommpanyName: string;<br>&nbsp; &nbsp; FileDescription: string;<br>&nbsp; &nbsp; FileVersion: string;<br>&nbsp; &nbsp; InternalName: string;<br>&nbsp; &nbsp; LegalCopyright: string;<br>&nbsp; &nbsp; LegalTrademarks: string;<br>&nbsp; &nbsp; OriginalFileName: string;<br>&nbsp; &nbsp; ProductName: string;<br>&nbsp; &nbsp; ProductVersion: string;<br>&nbsp; &nbsp; Comments: string;<br>&nbsp; &nbsp; VsFixedFileInfo:VS_FIXEDFILEINFO;<br>&nbsp; &nbsp; UserDefineValue:string;<br>&nbsp; end;<br><br>///UserDefine就是用户自定义的了,返回值保存在Info.UserDefineValue中<br><br>function GetFileVersionInfomation(const FileName: string; var info: TFileInfo;UserDefine:string=''):<br>&nbsp; boolean;<br>const<br>&nbsp; SFInfo= '/StringFileInfo/';<br>var<br>&nbsp; VersionInfo: Pointer;<br>&nbsp; InfoSize: DWORD;<br>&nbsp; InfoPointer: Pointer;<br>&nbsp; Translation: Pointer;<br>&nbsp; VersionValue: string;<br>&nbsp; unused: DWORD;<br>begin<br>&nbsp; unused := 0;<br>&nbsp; Result := False;<br>&nbsp; InfoSize := GetFileVersionInfoSize(pchar(FileName), unused);<br>&nbsp; if InfoSize &gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; GetMem(VersionInfo, InfoSize);<br>&nbsp; &nbsp; Result := GetFileVersionInfo(pchar(FileName), 0, InfoSize, VersionInfo);<br>&nbsp; &nbsp; if Result then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; VerQueryValue(VersionInfo, '/VarFileInfo/Translation', Translation, InfoSize);<br>&nbsp; &nbsp; &nbsp; VersionValue := SFInfo + IntToHex(LoWord(Longint(Translation^)), 4) +<br>&nbsp; &nbsp; &nbsp; &nbsp; IntToHex(HiWord(Longint(Translation^)), 4) + '/';<br>&nbsp; &nbsp; &nbsp; VerQueryValue(VersionInfo, pchar(VersionValue + 'CompanyName'), InfoPointer, InfoSize);<br>&nbsp; &nbsp; &nbsp; info.CommpanyName := string(pchar(InfoPointer));<br>&nbsp; &nbsp; &nbsp; VerQueryValue(VersionInfo, pchar(VersionValue + 'FileDescription'), InfoPointer, InfoSize);<br>&nbsp; &nbsp; &nbsp; info.FileDescription := string(pchar(InfoPointer));<br>&nbsp; &nbsp; &nbsp; VerQueryValue(VersionInfo, pchar(VersionValue + 'FileVersion'), InfoPointer, InfoSize);<br>&nbsp; &nbsp; &nbsp; info.FileVersion := string(pchar(InfoPointer));<br>&nbsp; &nbsp; &nbsp; VerQueryValue(VersionInfo, pchar(VersionValue + 'InternalName'), InfoPointer, InfoSize);<br>&nbsp; &nbsp; &nbsp; info.InternalName := string(pchar(InfoPointer));<br>&nbsp; &nbsp; &nbsp; VerQueryValue(VersionInfo, pchar(VersionValue + 'LegalCopyright'), InfoPointer, InfoSize);<br>&nbsp; &nbsp; &nbsp; info.LegalCopyright := string(pchar(InfoPointer));<br>&nbsp; &nbsp; &nbsp; VerQueryValue(VersionInfo, pchar(VersionValue + 'LegalTrademarks'), InfoPointer, InfoSize);<br>&nbsp; &nbsp; &nbsp; info.LegalTrademarks := string(pchar(InfoPointer));<br>&nbsp; &nbsp; &nbsp; VerQueryValue(VersionInfo, pchar(VersionValue + 'OriginalFileName'), InfoPointer, InfoSize);<br>&nbsp; &nbsp; &nbsp; info.OriginalFileName := string(pchar(InfoPointer));<br>&nbsp; &nbsp; &nbsp; VerQueryValue(VersionInfo, pchar(VersionValue + 'ProductName'), InfoPointer, InfoSize);<br>&nbsp; &nbsp; &nbsp; info.ProductName := string(pchar(InfoPointer));<br>&nbsp; &nbsp; &nbsp; VerQueryValue(VersionInfo, pchar(VersionValue + 'ProductVersion'), InfoPointer, InfoSize);<br>&nbsp; &nbsp; &nbsp; info.ProductVersion := string(pchar(InfoPointer));<br>&nbsp; &nbsp; &nbsp; VerQueryValue(VersionInfo, pchar(VersionValue + 'Comments'), InfoPointer, InfoSize);<br>&nbsp; &nbsp; &nbsp; info.Comments := string(pchar(InfoPointer));<br>&nbsp; &nbsp; &nbsp; if VerQueryValue(VersionInfo, '/', InfoPointer, InfoSize) then<br>&nbsp; &nbsp; &nbsp; &nbsp; info.VsFixedFileInfo := TVSFixedFileInfo(InfoPointer^);<br>&nbsp; &nbsp; &nbsp; if UserDefine&lt;&gt;'' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if VerQueryValue(VersionInfo,pchar(VersionValue+UserDefine),InfoPointer,InfoSize) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; info.UserDefineValue:=string(pchar(InfoPointer));<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; FreeMem(VersionInfo);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; info: TFileInfo;<br>begin<br>&nbsp; if OpenDialog1.Execute then<br>&nbsp; begin<br>&nbsp; &nbsp; if GetFileVersionInfomation(opendialog1.FileName, info,'WOW Version') then<br>////我必须知道'WOW Version'才能知道有这么一个自定义的串。如果用户定义的是'abc'我就没有办法取得了。<br>////而资源管理器的版本信息中就不一定需要知道。它可以找出所有的版本信息。<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Listbox1.Items.Add(OpenDialog1.FileName);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add('Comments:' + info.Comments);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add('CommpanyName:' + info.CommpanyName);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add('FileDescription:' + info.FileDescription);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add('FileVersion:' + info.FileVersion);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add('InternalName:' + info.InternalName);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add('LegalCopyright:' + info.LegalCopyright);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add('LegalTrademarks:' + info.LegalTrademarks);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add('OriginalFileName:' + info.OriginalFileName);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add('ProductName:' + info.ProductName);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add('ProductVersion:' + info.ProductVersion);<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add('UserDefineValue:' + info.UserDefineValue);<br>&nbsp; &nbsp; &nbsp; if boolean(info.VsFixedFileInfo.dwFileFlags and vs_FF_Debug) then<br>&nbsp; &nbsp; &nbsp; &nbsp;listbox1.Items.Add('Debug:True')<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp;ListBox1.Items.Add('Debug:False');<br>&nbsp; &nbsp; &nbsp; ListBox1.Items.Add(''); <br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br>问题很简单,就是实现资源管理其的文件属性--〉版本 中的功能。<br>实际上就是枚举文件的所有的用户自定义的版本信息字符串。
 
对这样的问题有点头疼。不好意思。
 
VersionValue<br>VersionValue<br>VersionValue<br>.........<br>我的头好晕
 
To WantLong:<br>&gt;&gt;我的头好晕<br>不会吧?你单步运行一下就知道了。
 
看不懂(骗分数,XIXI)
 
我踢!!!!!!!!!!!
 
我再踢!
 
看样子要被强制结束了.............
 
To 斑竹:<br>&nbsp; 如果在两周之内,没有人正确回答,请杀人兄进来,把分输给他~~~~~~~~~<br>&nbsp; 失望~~~~~~~~
 
呵呵,已经解决了.<br><br>杀人兄呢?快进来啊,我好结束他.
 
听说现在可以收回分数?我收回~~~~~~~~~~~
 
算了~~~~~~~`不知道有谁可以这样给分给我~~~~~~
 
后退
顶部