Browse Source

* reengineered utf8-less fix for #0031257

git-svn-id: trunk@36293 -
marco 8 years ago
parent
commit
f0a02cdaf9
1 changed files with 15 additions and 3 deletions
  1. 15 3
      rtl/objpas/sysutils/sysutils.inc

+ 15 - 3
rtl/objpas/sysutils/sysutils.inc

@@ -742,11 +742,23 @@ function SafeLoadLibrary(const FileName: AnsiString;
   end;
 
 function GetModuleName(Module: HMODULE): string;
-
+{$ifdef MSWINDOWS}
+var
+  ResultLength, BufferLength: DWORD;
+  Buffer: UnicodeString;
+{$endif}
 begin
 {$ifdef MSWINDOWS}
-  SetLength(Result,MAX_PATH);
-  SetLength(Result,GetModuleFileNameA(Module, Pchar(Result),Length(Result)));
+  BufferLength := MAX_PATH div 2;
+  repeat
+    Inc(BufferLength, BufferLength);
+    SetLength(Buffer, BufferLength);
+    ResultLength := GetModuleFileNameW(Module, Pointer(Buffer), BufferLength);
+    if ResultLength = 0 then
+      Exit('');
+  until ResultLength < BufferLength;
+  SetLength(Buffer, ResultLength);
+  Result := Buffer;
 {$ELSE}
   Result:='';
 {$ENDIF}