Pārlūkot izejas kodu

+ Add a new overload to DynLibs to allow loading by Ordinal only. This needs specific operating system support however and will return Nil (using a default implementation) if ordinals are not supported.
+ Implement overload for the three supported Windows targets.

git-svn-id: trunk@26457 -

svenbarth 11 gadi atpakaļ
vecāks
revīzija
6273192ce1
3 mainītis faili ar 25 papildinājumiem un 0 dzēšanām
  1. 12 0
      rtl/inc/dynlibs.pas
  2. 7 0
      rtl/win/dynlibs.inc
  3. 6 0
      rtl/wince/dynlibs.inc

+ 12 - 0
rtl/inc/dynlibs.pas

@@ -41,6 +41,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 UnloadLibrary(Lib : TLibHandle) : Boolean;
 Function GetLoadErrorStr: string;
 
@@ -58,6 +59,9 @@ 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 }
 {$i dynlibs.inc}
 
 {$ifndef FPCRTL_FILESYSTEM_TWO_BYTE_API}
@@ -140,6 +144,14 @@ begin
 end;
 {$endif not FPCRTL_FILESYSTEM_TWO_BYTE_API}
 
+{$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;
+begin
+  Result := Nil;
+end;
+{$endif not DYNLIBS_SUPPORTS_ORDINAL}
 
 Function FreeLibrary(Lib : TLibHandle) : Boolean;
 

+ 7 - 0
rtl/win/dynlibs.inc

@@ -48,6 +48,13 @@ begin
   Result:=Windows.GetProcAddress(Lib,PChar(ProcName));
 end;
 
+{$define DYNLIBS_SUPPORTS_ORDINAL}
+Function GetProcedureAddress(Lib : TLibHandle; Ordinal : Word) : Pointer;
+
+begin
+  Result:=Windows.GetProcAddress(Lib,PChar(Ordinal));
+end;
+
 Function UnloadLibrary(Lib : TLibHandle) : Boolean;
 
 begin

+ 6 - 0
rtl/wince/dynlibs.inc

@@ -50,6 +50,12 @@ begin
   FreeMem(ws);
 end;
 
+{$define DYNLIBS_SUPPORTS_ORDINAL}
+Function GetProcedureAddress(Lib : TLibHandle; Ordinal : Word) : Pointer;
+begin
+  Result:=Windows.GetProcAddress(Lib, PWideChar(Ordinal));
+end;
+
 Function UnloadLibrary(Lib : TLibHandle) : Boolean;
 begin
   Result:=Windows.FreeLibrary(Lib);