-
Notifications
You must be signed in to change notification settings - Fork 3
/
uFileVersion.pas
44 lines (37 loc) · 1 KB
/
uFileVersion.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
unit uFileVersion;
interface
function ReadVersion: String;
implementation
uses Forms, Windows, SysUtils;
function ReadVersion: String;
var
S: string;
n, Len: longword;
Buf: PChar;
Value: PChar;
CalcLangCharSet: String;
Temp: Integer;
begin
S := Application.ExeName;
n := GetFileVersionInfoSize(PChar(S), n);
Result := '';
if n > 0 then
begin
Buf := AllocMem(n);
GetFileVersionInfo(PChar(S), 0, n, Buf);
VerQueryValue(Buf, '\VarFileInfo\Translation', pointer(Value), Len);
if Len >= 4 then
begin
Temp := 0;
StrLCopy(@Temp, Value, 2);
CalcLangCharSet := IntToHex(Temp, 4);
StrLCopy(@Temp, Value + 2, 2);
CalcLangCharSet := CalcLangCharSet + IntToHex(Temp, 4);
end;
//if VerQueryValue(Buf, PChar('\StringFileInfo\040904E4\FileVersion'), Pointer(Value), Len) then
if VerQueryValue(Buf, PChar('\StringFileInfo\' + CalcLangCharSet + '\' + 'FileVersion'), Pointer(Value), Len) then
Result := Value;
FreeMem(Buf, n);
end;
end;
end.