浏览代码

+ 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 年之前
父节点
当前提交
6273192ce1
共有 3 个文件被更改,包括 25 次插入0 次删除
  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 LoadLibrary(const Name : UnicodeString) : TLibHandle;
 
 
 Function GetProcedureAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
 Function GetProcedureAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
+Function GetProcedureAddress(Lib : TLibHandle; Ordinal: Word) : Pointer;
 Function UnloadLibrary(Lib : TLibHandle) : Boolean;
 Function UnloadLibrary(Lib : TLibHandle) : Boolean;
 Function GetLoadErrorStr: string;
 Function GetLoadErrorStr: string;
 
 
@@ -58,6 +59,9 @@ Implementation
   OS - Independent declarations.
   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}
 {$i dynlibs.inc}
 
 
 {$ifndef FPCRTL_FILESYSTEM_TWO_BYTE_API}
 {$ifndef FPCRTL_FILESYSTEM_TWO_BYTE_API}
@@ -140,6 +144,14 @@ begin
 end;
 end;
 {$endif not FPCRTL_FILESYSTEM_TWO_BYTE_API}
 {$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;
 Function FreeLibrary(Lib : TLibHandle) : Boolean;
 
 

+ 7 - 0
rtl/win/dynlibs.inc

@@ -48,6 +48,13 @@ begin
   Result:=Windows.GetProcAddress(Lib,PChar(ProcName));
   Result:=Windows.GetProcAddress(Lib,PChar(ProcName));
 end;
 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;
 Function UnloadLibrary(Lib : TLibHandle) : Boolean;
 
 
 begin
 begin

+ 6 - 0
rtl/wince/dynlibs.inc

@@ -50,6 +50,12 @@ begin
   FreeMem(ws);
   FreeMem(ws);
 end;
 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;
 Function UnloadLibrary(Lib : TLibHandle) : Boolean;
 begin
 begin
   Result:=Windows.FreeLibrary(Lib);
   Result:=Windows.FreeLibrary(Lib);