简体   繁体   中英

Get File Version for Delphi XE2 and later

I'm updating a program to Delphi XE7 from Delphi 2010. The code shown below has stopped working due I think to the need to adapt for unicode and to use GetFileVersionInfoW instead of GetFileVersionInfoSize.

Has anyone developed a more up-to-date version of the function I was using shown below? I can't find any examples so far on the web and I'm afraid that low level windows programming is a bit beyond me.

Thanks for any help!

Old Code Below No Longer works on Delphi XE2 and later: just returns 1.0.0.0

procedure GetBuildInfo(var V1, V2, V3, V4: Word);
{From Steve Schafer }
var
  VerInfoSize: DWORD;
  VerInfo: pointer;
  VerValueSize: DWORD;
  VerValue: PVSFixedFileInfo;
  Dummy: DWORD;

begin
  VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
  GetMem(VerInfo, VerInfoSize);
  GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo);
  VerQueryValue(VerInfo, '\', pointer(VerValue), VerValueSize);
  with VerValue^ do
    begin
      V1 := dwFileVersionMS shr 16;
      V2 := dwFileVersionMS and $FFFF;
      V3 := dwFileVersionLS shr 16;
      V4 := dwFileVersionLS and $FFFF;
    end;
  FreeMem(VerInfo, VerInfoSize);
end;

Your code works perfectly well when compiled by all versions of Delphi. The only logical conclusion therefore, as to why the code reports a version of 1.0.0.0 is that the version is 1.0.0.0 .

In other words your problem will not be found by looking at this code. Your problem will be found by working out why you are not managing to set the version information a you intend when compiling.

It is probably also worth pointing out that your code makes no attempt to check return values for errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM