Get FileVersion Using Build

DelphiXe.

To get the file version, I use the function:

function FileVersion(AFileName: string): string; var szName: array[0..255] of Char; P: Pointer; Value: Pointer; Len: UINT; GetTranslationString: string; FFileName: PChar; FValid: boolean; FSize: DWORD; FHandle: DWORD; FBuffer: PChar; begin try FFileName := StrPCopy(StrAlloc(Length(AFileName) + 1), AFileName); FValid := False; FSize := GetFileVersionInfoSize(FFileName, FHandle); if FSize > 0 then try GetMem(FBuffer, FSize); FValid := GetFileVersionInfo(FFileName, FHandle, FSize, FBuffer); except FValid := False; raise; end; Result := ''; if FValid then VerQueryValue(FBuffer, '\VarFileInfo\Translation', p, Len) else p := nil; if P <> nil then GetTranslationString := IntToHex(MakeLong(HiWord(Longint(P^)), LoWord(Longint(P^))), 8); if FValid then begin StrPCopy(szName, '\StringFileInfo\' + GetTranslationString + '\FileVersion'); if VerQueryValue(FBuffer, szName, Value, Len) then Result := StrPas(PChar(Value)); end; finally try if FBuffer <> nil then FreeMem(FBuffer, FSize); except end; try StrDispose(FFileName); except end; end; end; 

For most executables and libraries, it returns the correct value. But in some files, the version is disabled and shown without assembly. For example, the BASS.DLL file (http://us.un4seen.com/files/bass24.zip) In Windows Explorer, in the file properties I see version 2.4.7.1, function result = '2.4.7': (

I open the file through Resourcehacker.exe (http://angusj.com/resourcehacker/), I look at the VersionInfo structure:

 1 VERSIONINFO FILEVERSION 2,4,7,1 PRODUCTVERSION 2,4,0,0 FILEOS 0x4 FILETYPE 0x2 { BLOCK "StringFileInfo" { BLOCK "000004b0" { VALUE "CompanyName", "Un4seen Developments" VALUE "FileDescription", "BASS" VALUE "FileVersion", "2.4.7" VALUE "LegalCopyright", "Copyright Β© 1999-2010" } } BLOCK "VarFileInfo" { VALUE "Translation", 0x0000 0x04B0 } } 

Question: how to get 2.4.7.1, i.e. full version?

+4
source share
2 answers

If you want a version of the root block file, forget about the language-specific translation:

 function FileVersion(const FileName: TFileName): String; var VerInfoSize: Cardinal; VerValueSize: Cardinal; Dummy: Cardinal; PVerInfo: Pointer; PVerValue: PVSFixedFileInfo; begin Result := ''; VerInfoSize := GetFileVersionInfoSize(PChar(FileName), Dummy); GetMem(PVerInfo, VerInfoSize); try if GetFileVersionInfo(PChar(FileName), 0, VerInfoSize, PVerInfo) then if VerQueryValue(PVerInfo, '\', Pointer(PVerValue), VerValueSize) then with PVerValue^ do Result := Format('v%d.%d.%d build %d', [ HiWord(dwFileVersionMS), //Major LoWord(dwFileVersionMS), //Minor HiWord(dwFileVersionLS), //Release LoWord(dwFileVersionLS)]); //Build finally FreeMem(PVerInfo, VerInfoSize); end; end; 
+10
source

If you want to edit the BASS audio library (which you cannot). The reason is that it is compressed with the help of β€œPetite v1.4,” which Ian wants people to not be able to easily edit it.

Also, to get the version of bass.dll, it has an export, which when used, you can get the absolute version, as you want, without a big hack, and what not.

0
source

All Articles