From c0487d7ef928a2aaa6f07f55e018205b8665edca Mon Sep 17 00:00:00 2001
From: michael <michael@freepascal.org>
Date: Sat, 5 Mar 2016 15:00:40 +0000
Subject: [PATCH] * Fix bug ID #29784

git-svn-id: trunk@33154 -
---
 rtl/win/sysutils.pp | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/rtl/win/sysutils.pp b/rtl/win/sysutils.pp
index 7f170f72f4..4197322435 100644
--- a/rtl/win/sysutils.pp
+++ b/rtl/win/sysutils.pp
@@ -78,6 +78,7 @@ function CheckWin32Version(Major : Integer): Boolean;
 Procedure RaiseLastWin32Error;
 
 function GetFileVersion(const AFileName: string): Cardinal;
+function GetFileVersion(const AFileName: UnicodeString): Cardinal;
 
 procedure GetFormatSettings;
 procedure GetLocaleFormatSettings(LCID: Integer; var FormatSettings: TFormatSettings); platform;
@@ -155,6 +156,39 @@ function GetFileVersion(const AFileName:string):Cardinal;
       end;
   end;
 
+function GetFileVersion(const AFileName:UnicodeString):Cardinal;
+  var
+    { useful only as long as we don't need to touch different stack pages }
+    buf : array[0..3071] of byte;
+    bufp : pointer;
+    fn : unicodestring;
+    valsize,
+    size : DWORD;
+    h : DWORD;
+    valrec : PVSFixedFileInfo;
+  begin
+    result:=$fffffff;
+    fn:=AFileName;
+    UniqueString(fn);
+    size:=GetFileVersionInfoSizeW(pwidechar(fn),@h);
+    if size>sizeof(buf) then
+      begin
+        getmem(bufp,size);
+        try
+          if GetFileVersionInfoW(pwidechar(fn),h,size,bufp) then
+            if VerQueryValue(bufp,'\',valrec,valsize) then
+              result:=valrec^.dwFileVersionMS;
+        finally
+          freemem(bufp);
+        end;
+      end
+    else
+      begin
+        if GetFileVersionInfoW(pwidechar(fn),h,size,@buf) then
+          if VerQueryValueW(@buf,'\',valrec,valsize) then
+            result:=valrec^.dwFileVersionMS;
+      end;
+  end;
 
 {$define HASCREATEGUID}
 {$define HASEXPANDUNCFILENAME}