[Lazarus] Program version
pascaldragon at googlemail.com
Wed Nov 6 16:31:24 CET 2013
Am 06.11.2013 16:07, schrieb Antonio Fortuny:
> Le 06/11/2013 15:46, Anton Kavalenka a écrit :
>> Handle of EXE (hInstance) or .SO hMod:=Loadlibrary(dll_name);
> Works fine on Win32 with *hInstance*: great ! 8-)
> I guess it will run on Linux too
> The code I use for Linux is the next one, which works almost the same
> except that the source is a file:
> function ReadVersionInfo(const sProgram: string; Out vv: String) :Boolean;
> RS : TResources;
> E : TElfResourceReader;
> VR : TVersionResource;
> I : Integer;
> Result := False; //no version info at all in the file
> While (VR=Nil) and (I<RS.Count) do begin
> if RS.Items[i] is TVersionResource then
> if Result then begin
> vv:= Format('%d.%d.%d.%d',[VR.FixedInfo.FileVersion,
> VR.FixedInfo.FileVersion, VR.FixedInfo.FileVersion,
> End ;
> Question is: does an equivalent to the "T*Elf*ResourceReader" exist
> for Windows executable files ?
> I'm pretty sure that you do guess what I'm trying to do: have only one
> fuction to retrieve the version of any program on any platform. If a
> version using a file name can be setup, wonking on the current program
> is easy: check on ParamStr(0).
> Maybe a couple of [$IFDEF ...} will be needed but this is not an issue.
> BTW, if the procedure works for WinCE too I'll be the happiest man on
> If this piece of code could be helpfull to others, it could be
> integrated to FPC or Lazarus, whatever.
> It will need some rewriting though.
If you look at my other mail you'll see the solution. The reader unit
for Windows PE files is WinPEImageReader. And you can avoid ifdefs by
additionally to unit "resources" using the units "elfreader",
"winpeimagereader" and "versionresource". Then you can do
"Rs.LoadFromFile(sProgram);" (the explicit reader isn't needed as the
extension will be used) and either loop through all resources like you
currently do or use "Rs.Find(RT_VERSION, 1)" which should(!) return you
the correct version resource.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Lazarus