Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 Oct : Read version info from EXE
| Subject: | Read version info from EXE |
| Posted by: | "Mikael Lenfors" (mika..@lenfors.se) |
| Date: | Wed, 18 Oct 2006 12:09:14 |
Hello!
I use the code below for reading the version of an EXE file. My only problem
is that it does nor work :-)
The VerQueryValue always returns False. GetFileVersionInfoSize seems ok and
returns a size. Any ideas? By the way, it's Delphi Studio 2006.
Regards, Mikael
Function FileVersion(FileName: String): String;
var Buff: PChar;
BuffSize: DWORD;
InfoPtr: PChar;
RsltLen: DWORD;
Begin
Result := '???';
// If no filname assume myself
If FileName = '' Then
FileName := ParamStr(0);
// Read size of infoblock
BuffSize := GetFileVersionInfoSize(PChar(FileName), BuffSize);
If BuffSize > 0 Then
Begin
Buff := AllocMem(BuffSize);
Try
If GetFileVersionInfo(PChar(FileName), 0, BuffSize, Buff) Then
Begin
If VerQueryValue(Buff, PChar('StringFileInfo\040904E4\FileVersion'),
Pointer(InfoPtr), RsltLen) Then
Begin
Result := InfoPtr;
End;
End; // Read FileversionInfo
Finally
FreeMem(Buff, BuffSize);
End;
End; // Size of info > 0
End;