得到EXE文件本身的文件版本信息,D7的帮助文件的例子 为何不行? ( 积分: 50 )

  • 主题发起人 主题发起人 delhpi
  • 开始时间 开始时间
D

delhpi

Unregistered / Unconfirmed
GUEST, unregistred user!
ou can use the Windows GetFileVersionInfo and VerQueryValue API functions to obtain version information that is compiled with your application. The following code illustrates how to do this by writing the version information to a memo control named Memo1:

procedure TForm1.Button1Click(Sender: TObject);

const
InfoNum = 10;
InfoStr: array[1..InfoNum] of string = ('CompanyName', 'FileDescription', 'FileVersion', 'InternalName', 'LegalCopyright', 'LegalTradeMarks', 'OriginalFileName', 'ProductName', 'ProductVersion', 'Comments');
var
S: string;
n, Len, i: DWORD;
Buf: PChar;
Value: PChar;
begin
S := Application.ExeName;
n := GetFileVersionInfoSize(PChar(S), n);
if n > 0 then
begin

Buf := AllocMem(n);
Memo1.Lines.Add('VersionInfoSize = ' + IntToStr(n));
GetFileVersionInfo(PChar(S), 0, n, Buf);
for i := 1 to InfoNum do
if VerQueryValue(Buf, PChar('StringFileInfo/040904E4/' + InfoStr), Pointer(Value), Len) then //这句话,不明白,是否要修改一下?
Memo1.Lines.Add(InfoStr + ' = ' + Value);
FreeMem(Buf, n);
end
else
Memo1.Lines.Add('No version information found');
end;
 
/StringFileInfo/lang-charset/string-name

Specifies a value in a language-specific structure. The lang-charset name is a concatenation of a language and character-set identifier pair found in the translation table for the resource. The lang-charset name must be specified as a hexadecimal string.

看了SDK说明,知道 lang-charset 是语言字符集,lang=0804,charset是多少?
 
查了一下 全文检索,惭愧,都已经讨论过了。
 
**********************************
获取文件版本信息
type
TFileInfo = packed record
CommpanyName: string;
FileDescription: string;
FileVersion: string;
InternalName: string;
LegalCopyright: string;
LegalTrademarks: string;
OriginalFileName: string;
ProductName: string;
ProductVersion: string;
Comments: string;
VsFixedFileInfo:VS_FIXEDFILEINFO;
UserDefineValue:string;
end;

function GetFileVersionInfomation(const FileName: string; var info: TFileInfo;UserDefine:string=''):
boolean;
const
SFInfo= '/StringFileInfo/';
var
VersionInfo: Pointer;
InfoSize: DWORD;
InfoPointer: Pointer;
Translation: Pointer;
VersionValue: string;
unused: DWORD;
begin
unused := 0;
Result := False;
InfoSize := GetFileVersionInfoSize(pchar(FileName), unused);
if InfoSize > 0 then
begin
GetMem(VersionInfo, InfoSize);
Result := GetFileVersionInfo(pchar(FileName), 0, InfoSize, VersionInfo);
if Result then
begin
VerQueryValue(VersionInfo, '/VarFileInfo/Translation', Translation, InfoSize);
VersionValue := SFInfo + IntToHex(LoWord(Longint(Translation^)), 4) +
IntToHex(HiWord(Longint(Translation^)), 4) + '/';
==============================
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1623418
这个帖子中的函数,下面这句,编译通过,在运行时报错,应该是取 lang-charset。
VersionValue := SFInfo + IntToHex(LoWord(Longint(Translation^)), 4) +
IntToHex(HiWord(Longint(Translation^)), 4) + '/';


---------------------------
Debugger Exception Notification
---------------------------
Project test2Project1.exe raised exception class EAccessViolation with message 'Access violation at address 77B6200E in module 'version.dll'. Write of address 0044228A'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
 
接受答案了.
 
后退
顶部