Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Get file version - something wrong (https://www.delphipraxis.net/181424-get-file-version-something-wrong.html)

WojTec 13. Aug 2014 10:41

Delphi-Version: XE5

Get file version - something wrong
 
I want to get version info from executable, so I checked MSDN and wrote something like this:

Delphi-Quellcode:
  Size := GetFileVersionInfoSize(PChar(AFileName), hWnd);
  if Size > 0 then
  begin
    GetMem(Buffer, Size);
    try
      if GetFileVersionInfo(PChar(AFileName), hWnd, Size, Buffer) then
      begin
        if VerQueryValue(Buffer, '\', Pointer(FixedFileInfo), L) then
        begin
          if VerQueryValue(Buffer, PChar('\VarFileInfo\Translation'), Pointer(pD), L) then
          begin
            Translation := IntToHex(pD^, 8);
            Temp := Copy(Translation, 5, 4);
            if StrToIntDef('$' + Temp, 0) = 0 then
              Temp := IntToHex(1033, 4)
            ;
            Translation := Temp + Copy(Translation, 1, 4);
          end
          else
            Translation := '040904E4'
          ;

          // Here query for values
I checked on 16, 32 and 64 bit files and working well in most cases, but not for all :shock: For example for firefox.exe returns nulls (but query for translation passes) :roll: What's wrong with this? :?

Der schöne Günther 13. Aug 2014 10:46

AW: Get file version - something wrong
 
You already know of a scenario that is going to fail. And you have the might of the debugger at your fingertips. What's stopping you from first finding out which call returns NULL?

WojTec 13. Aug 2014 11:39

Re: AW: Get file version - something wrong
 
So, I told

Delphi-Quellcode:
VerQueryValue(Buffer, PChar('\VarFileInfo\Translation')...


is success. Problem is with

Delphi-Quellcode:
VerQueryValue(Buffer, PChar('\StringFileInfo\' + Translation + '\(specified entries in table here)')


- here it fails on some files, looks like can't access, because wrong translation code :?

Whookie 13. Aug 2014 21:50

AW: Get file version - something wrong
 
Liste der Anhänge anzeigen (Anzahl: 1)
Heres an example how I'm doing it (see attachement).. its ripped from my component library and displays some of the version info in a memo.

WojTec 14. Aug 2014 13:32

Re: Get file version - something wrong
 
Nice, thanks! It woreking very well. :)

I did something wrong with translation I see.


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:48 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz