Browse Source

--- Merging r21880 into '.':
U rtl/unix/dynlibs.inc
U rtl/wince/dynlibs.inc
U rtl/netwlibc/dynlibs.inc
U rtl/win/dynlibs.inc
U rtl/os2/dynlibs.inc
U rtl/netware/dynlibs.inc
U rtl/inc/dynlibs.pas
--- Merging r21891 into '.':
G rtl/win/dynlibs.inc
--- Merging r21907 into '.':
G rtl/os2/dynlibs.inc
--- Merging r21908 into '.':
G rtl/os2/dynlibs.inc
--- Merging r21935 into '.':
G rtl/wince/dynlibs.inc
--- Merging r21936 into '.':
G rtl/wince/dynlibs.inc
--- Merging r21937 into '.':
G rtl/wince/dynlibs.inc

# revisions: 21880,21891,21907,21908,21935,21936,21937
r21880 | michael | 2012-07-11 17:31:09 +0200 (Wed, 11 Jul 2012) | 1 line
Changed paths:
M /trunk/rtl/inc/dynlibs.pas
M /trunk/rtl/netware/dynlibs.inc
M /trunk/rtl/netwlibc/dynlibs.inc
M /trunk/rtl/os2/dynlibs.inc
M /trunk/rtl/unix/dynlibs.inc
M /trunk/rtl/win/dynlibs.inc
M /trunk/rtl/wince/dynlibs.inc

* Added GetLoadErrorStr function by Mark Morgan Loyd (Bug ID 22321)
r21891 | michael | 2012-07-12 10:37:40 +0200 (Thu, 12 Jul 2012) | 1 line
Changed paths:
M /trunk/rtl/win/dynlibs.inc

* Fixed compilation
r21907 | hajny | 2012-07-13 01:30:19 +0200 (Fri, 13 Jul 2012) | 1 line
Changed paths:
M /trunk/rtl/os2/dynlibs.inc

* GetLoadErrorStr implemented
r21908 | hajny | 2012-07-13 01:32:51 +0200 (Fri, 13 Jul 2012) | 1 line
Changed paths:
M /trunk/rtl/os2/dynlibs.inc

* correction for copy&paste error in previous commit
r21935 | michael | 2012-07-18 09:36:24 +0200 (Wed, 18 Jul 2012) | 1 line
Changed paths:
M /trunk/rtl/wince/dynlibs.inc

* No SysErrorMessage on WinCE ?
r21936 | michael | 2012-07-18 09:38:21 +0200 (Wed, 18 Jul 2012) | 1 line
Changed paths:
M /trunk/rtl/wince/dynlibs.inc

* Copied non-sysutils solution of win32/64
r21937 | michael | 2012-07-18 11:17:30 +0200 (Wed, 18 Jul 2012) | 1 line
Changed paths:
M /trunk/rtl/wince/dynlibs.inc

* FormatMessageA -> FormatMessage (W version)

git-svn-id: branches/fixes_2_6@22545 -

marco 13 years ago
parent
commit
1c767da80e

+ 1 - 0
rtl/inc/dynlibs.pas

@@ -37,6 +37,7 @@ Function SafeLoadLibrary(const Name : AnsiString) : TLibHandle;
 Function LoadLibrary(const Name : AnsiString) : TLibHandle;
 Function GetProcedureAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
 Function UnloadLibrary(Lib : TLibHandle) : Boolean;
+Function GetLoadErrorStr: string;
 
 // Kylix/Delphi compability
 

+ 6 - 0
rtl/netware/dynlibs.inc

@@ -56,5 +56,11 @@ begin
   Result:=false;
 end;
 
+
+Function GetLoadErrorStr: string;
+
+begin  
+  Result:='';
+end;
 {$endif}
 

+ 5 - 0
rtl/netwlibc/dynlibs.inc

@@ -53,5 +53,10 @@ begin
   Result:=dlClose(Lib)=0;
 end;
 
+Function GetLoadErrorStr: string;
+
+begin  
+  Result:='';
+end;
 {$endif}
 

+ 57 - 7
rtl/os2/dynlibs.inc

@@ -37,27 +37,77 @@ const
 uses
  DosCalls;
 
+threadvar
+ DynLibErrNo: cardinal;
+ DynLibErrPath: array [0..259] of char;
+
 function LoadLibrary (const Name: AnsiString): TLibHandle;
 var
- ErrPath: array [0..259] of char;
  Handle: longint;
 begin
- if DosLoadModule (@ErrPath, SizeOf (ErrPath), PChar (Name), Handle) = 0
-                                then Result := Handle else Result := NilHandle;
+ DynLibErrPath [0] := #0;
+ DynLibErrNo := DosLoadModule (@DynLibErrPath [0], SizeOf (DynLibErrPath),
+                                                         PChar (Name), Handle);
+ if DynLibErrNo = 0 then
+  Result := Handle
+ else
+  Result := NilHandle;
 end;
 
 function GetProcedureAddress (Lib: TLibHandle; const ProcName: AnsiString): pointer;
 var
  P: pointer;
 begin
- if DosQueryProcAddr (Lib, 0, PChar (ProcName), P) = 0 then Result := P
-                                                            else Result := nil;
+ DynLibErrPath [0] := #0;
+ DynLibErrNo := DosQueryProcAddr (Lib, 0, PChar (ProcName), P);
+ if DynLibErrNo = 0 then
+  Result := P
+ else
+  Result := nil;
 end;
 
 function UnloadLibrary (Lib: TLibHandle): boolean;
 begin
- Result := DosFreeModule (Lib) = 0;
+ DynLibErrPath [0] := #0;
+ DynLibErrNo := DosFreeModule (Lib);
+ Result := DynLibErrNo = 0;
 end;
 
-{$endif}
+function GetDynLibsError: longint;
+begin
+ GetDynLibsError := DynLibErrNo;
+end;
+
+function GetDynLibsErrorStr: string;
+const
+ SysMsgFile: array [0..10] of char = 'OSO001.MSG'#0;
+var
+ VarArr: array [1..9] of PChar;
+ OutBuf: array [0..999] of char;
+ RetMsgSize: cardinal;
+ RC: cardinal;
+begin
+ if DynLibErrNo = 0 then
+  GetDynLibsErrorStr := ''
+ else
+  begin
+   VarArr [1] := @DynLibErrPath [0];
+   RC := DosGetMessage (@VarArr, 1, @OutBuf [0], SizeOf (OutBuf),
+                                     DynLibErrNo, @SysMsgFile [0], RetMsgSize);
+   if RC = 0 then
+    Result := StrPas (@OutBuf [0])
+   else
+    begin
+     WriteStr (Result, DynLibErrNo);
+     Result := 'Error ' + Result;
+    end;
+   if DynLibErrPath [0] <> #0 then
+    Result := StrPas (@DynLibErrPath [0]) + ' - ' + Result;
+  end;
+end;
 
+function GetLoadErrorStr: string;
+begin
+ GetLoadErrorStr := GetDynLibsErrorStr;
+end;
+{$endif}

+ 6 - 0
rtl/unix/dynlibs.inc

@@ -58,5 +58,11 @@ begin
   Result:=dlClose(Lib)=0;
 end;
 
+Function GetLoadErrorStr: string;
+
+begin
+  Result:=dl.dlerror;
+end;
+
 {$endif}
 

+ 14 - 0
rtl/win/dynlibs.inc

@@ -54,5 +54,19 @@ begin
   Result:=Windows.FreeLibrary(Lib);
 end;
 
+Function GetLoadErrorStr: string;
+
+Var
+  rc,c : integer;
+  
+begin  
+  rc := GetLastError;
+  SetLength(Result,255);
+  C:=FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,nil,rc,
+                 MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                 @Result[1], 255,nil);
+  SetLength(Result,c);
+end;
+
 {$endif}
 

+ 16 - 0
rtl/wince/dynlibs.inc

@@ -59,4 +59,20 @@ begin
   Result:=Windows.FreeLibrary(Lib);
 end;
 
+Function GetLoadErrorStr: string;
+
+Var
+  rc,c : integer;
+  w : widestring;
+  
+begin  
+  rc := GetLastError;
+  SetLength(w,255);
+  C:=FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,nil,rc,
+                 MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                 @W[1], 255,nil);
+  SetLength(w,c);
+  Result:=w;
+end;
+
 {$endif}