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?