[DUG] VersionInfo
Laurence Bevan
Laurence at master.co.nz
Mon May 8 11:05:16 NZST 2006
A routine to extract the version of the running app:
function GetExeVersionStr: string;
var
Dummy: DWORD;
FileVerInfoSize: integer;
Buffer: PChar;
PFFI: PVSFixedFileInfo;
FFISize: DWORD;
begin
FileVerInfoSize := GetFileVersionInfoSize(PChar(Application.EXEName), Dummy);
if FileVerInfoSize = 0 then
begin
Result := '';
Exit;
end;
GetMem(Buffer, FileVerInfoSize);
try
GetFileVersionInfo(PChar(Application.EXEName), 0,
FileVerInfoSize, Buffer);
VerQueryValue(Buffer, '\', pointer(PFFI), FFISize);
Result := Format('%d.%d.%d build %d',
[HiWord(PFFI^.dwFileVersionMS),
LoWord(PFFI^.dwFileVersionMS),
HiWord(PFFI^.dwFileVersionLS),
LoWord(PFFI^.dwFileVersionLS)]);
finally
FreeMem(Buffer, FileVerInfoSize);
end;
end;
An extended version for getting version info from another file:
function GetExeVersionStrEx(Filename: String): TVersion;
var
Dummy: DWORD;
FileVerInfoSize: integer;
Buffer: PChar;
PFFI: PVSFixedFileInfo;
FFISize: DWORD;
begin
Result.Major := 0 ;
Result.Minor := 0 ;
Result.Incr := 0 ;
Result.Build := 0 ;
if FileExists(Filename) then
begin
FileVerInfoSize := GetFileVersionInfoSize(PChar(Filename), Dummy);
if FileVerInfoSize = 0 then
Exit;
GetMem(Buffer, FileVerInfoSize);
try
GetFileVersionInfo(PChar(Filename), 0,
FileVerInfoSize, Buffer);
VerQueryValue(Buffer, '\', pointer(PFFI), FFISize);
Result.Major := HiWord(PFFI^.dwFileVersionMS) ;
Result.Minor := LoWord(PFFI^.dwFileVersionMS) ;
Result.Incr := HiWord(PFFI^.dwFileVersionLS) ;
Result.Build := LoWord(PFFI^.dwFileVersionLS) ;
Result.Version := Format('%d.%d.%d build %d', [Result.Major, Result.Minor, Result.Incr,
Result.Build])
finally
FreeMem(Buffer, FileVerInfoSize);
end;
end ;
end;
Cheers,
Laurence Bevan
Master Business Systems Ltd
PO Box 467
Feilding 5600
Phone 027-228-8331
Email laurence at master.co.nz
Web http://www.master.co.nz
----- Original Message -----
From: Rohit Gupta
To: NZ Borland Developers Group - Delphi List <delphi at ns3.123.co.nz>
Sent: Mon, 08 May 2006 10:54:12 +1200
Subject: [DUG] VersionInfo
Is there an easy way for an application to obtain the version info from
1. Its own resource
2. Some other app/dll
_______________________________________________
Delphi mailing list
Delphi at ns3.123.co.nz
http://ns3.123.co.nz/mailman/listinfo/delphi
More information about the Delphi
mailing list