From 1a430d81101e0c75a28d45e6a95fb8aa3d3c244a Mon Sep 17 00:00:00 2001
From: Tomas Hajny <hajny@freepascal.org>
Date: Sun, 19 Jan 2014 21:15:26 +0000
Subject: [PATCH]   * GetProcAddr added for OS/2, type of argument for ordinal
 target specific now

git-svn-id: trunk@26521 -
---
 rtl/inc/dynlibs.pas | 18 ++++++++++++------
 rtl/os2/dynlibs.inc | 15 +++++++++++++++
 rtl/win/dynlibs.inc |  4 +++-
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/rtl/inc/dynlibs.pas b/rtl/inc/dynlibs.pas
index 7241a97932..9b276093a0 100644
--- a/rtl/inc/dynlibs.pas
+++ b/rtl/inc/dynlibs.pas
@@ -26,6 +26,10 @@ interface
   Read OS-dependent interface declarations.
   ---------------------------------------------------------------------}
 
+{ Note: should define the TOrdinalEntry type and define
+        DYNLIBS_SUPPORTS_ORDINAL if the operating system supports loading
+        functions by a ordinal like e.g. Windows or OS/2 do }
+
 {$define readinterface}
 {$i dynlibs.inc}
 {$undef  readinterface}
@@ -33,7 +37,10 @@ interface
 { ---------------------------------------------------------------------
   OS - Independent declarations.
   ---------------------------------------------------------------------}
-
+{$IFNDEF DYNLIBS_SUPPORTS_ORDINAL}
+type
+ TOrdinalEntry = SizeUInt;
+{$ENDIF DYNLIBS_SUPPORTS_ORDINAL}
 
 Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle;
 Function LoadLibrary(const Name : RawByteString) : TLibHandle;
@@ -41,7 +48,7 @@ Function SafeLoadLibrary(const Name : UnicodeString) : TLibHandle;
 Function LoadLibrary(const Name : UnicodeString) : TLibHandle;
 
 Function GetProcedureAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
-Function GetProcedureAddress(Lib : TLibHandle; Ordinal: Word) : Pointer;
+Function GetProcedureAddress(Lib : TLibHandle; Ordinal: TOrdinalEntry) : Pointer;
 Function UnloadLibrary(Lib : TLibHandle) : Boolean;
 Function GetLoadErrorStr: string;
 
@@ -59,9 +66,8 @@ Implementation
   OS - Independent declarations.
   ---------------------------------------------------------------------}
 
-{ Note: should define the Word overload and define DYNLIBS_SUPPORTS_ORDINAL if
-        the operating system supports loading functions by a ordinal like e.g.
-        Windows or OS/2 do }
+{ Note: should define the TOrdinalEntry overload if the operating system
+        supports loading functions by a ordinal like e.g. Windows or OS/2 do }
 {$i dynlibs.inc}
 
 {$ifndef FPCRTL_FILESYSTEM_TWO_BYTE_API}
@@ -147,7 +153,7 @@ end;
 {$ifndef DYNLIBS_SUPPORTS_ORDINAL}
 { OS does not support loading by ordinal (or it's not implemented yet), so by
   default we simply return Nil }
-Function GetProcedureAddress(Lib : TLibHandle; Ordinal : Word) : Pointer;
+Function GetProcedureAddress(Lib : TLibHandle; Ordinal : TOrdinalEntry) : Pointer;
 begin
   Result := Nil;
 end;
diff --git a/rtl/os2/dynlibs.inc b/rtl/os2/dynlibs.inc
index 69b35cbba7..ac37305fe1 100644
--- a/rtl/os2/dynlibs.inc
+++ b/rtl/os2/dynlibs.inc
@@ -20,8 +20,11 @@
     Interface declarations
   ---------------------------------------------------------------------}
 
+{$DEFINE DYNLIBS_SUPPORTS_ORDINAL}
+
 type
  TLibHandle = longint;
+ TOrdinalEntry = cardinal;
 
 const
  NilHandle = 0;
@@ -66,6 +69,18 @@ begin
   Result := nil;
 end;
 
+function GetProcedureAddress (Lib: TLibHandle; Ordinal: TOrdinalEntry): pointer;
+var
+ P: pointer;
+begin
+ DynLibErrPath [0] := #0;
+ DynLibErrNo := DosQueryProcAddr (Lib, Ordinal, nil, P);
+ if DynLibErrNo = 0 then
+  Result := P
+ else
+  Result := nil;
+end;
+
 function UnloadLibrary (Lib: TLibHandle): boolean;
 begin
  DynLibErrPath [0] := #0;
diff --git a/rtl/win/dynlibs.inc b/rtl/win/dynlibs.inc
index 073ea5c2f6..3da84fd570 100644
--- a/rtl/win/dynlibs.inc
+++ b/rtl/win/dynlibs.inc
@@ -20,8 +20,11 @@
     Interface declarations
   ---------------------------------------------------------------------}
 
+{$define DYNLIBS_SUPPORTS_ORDINAL}
+
 Type
   TLibHandle = System.THandle;
+  TOrdinalEntry = word;
 
 Const
   NilHandle = 0;
@@ -48,7 +51,6 @@ begin
   Result:=Windows.GetProcAddress(Lib,PChar(ProcName));
 end;
 
-{$define DYNLIBS_SUPPORTS_ORDINAL}
 Function GetProcedureAddress(Lib : TLibHandle; Ordinal : Word) : Pointer;
 
 begin