dynlibs.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. Implements OS-independent loading of dynamic libraries.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$IFDEF FPC}
  12. {$MODE OBJFPC}
  13. {$ENDIF}
  14. unit dynlibs;
  15. interface
  16. Type
  17. TLibHandle = System.TLibHandle;
  18. Const
  19. NilHandle = System.NilHandle;
  20. SharedSuffix = System.SharedSuffix;
  21. Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle; inline;
  22. Function LoadLibrary(const Name : RawByteString) : TLibHandle; inline;
  23. Function SafeLoadLibrary(const Name : UnicodeString) : TLibHandle; inline;
  24. Function LoadLibrary(const Name : UnicodeString) : TLibHandle; inline;
  25. Function GetProcedureAddress(Lib : TlibHandle; const ProcName : AnsiString) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif}; inline;
  26. Function GetProcedureAddress(Lib : TLibHandle; Ordinal: TOrdinalEntry) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif}; inline;
  27. Function UnloadLibrary(Lib : TLibHandle) : Boolean; inline;
  28. Function GetLoadErrorStr: string; inline;
  29. // Kylix/Delphi compability
  30. Function FreeLibrary(Lib : TLibHandle) : Boolean; inline;
  31. Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif}; inline;
  32. Type
  33. HModule = TLibHandle;
  34. Implementation
  35. { Should define a procedure InitDynLibs which sets up the DynLibs manager; optionally a
  36. DoneDynLibs can be defined which is called during finalization }
  37. {$i dynlibs.inc}
  38. Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle;
  39. begin
  40. Result:=System.SafeLoadLibrary(Name);
  41. end;
  42. Function LoadLibrary(const Name : RawByteString) : TLibHandle;
  43. begin
  44. Result:=System.LoadLibrary(Name);
  45. end;
  46. Function SafeLoadLibrary(const Name : UnicodeString) : TLibHandle;
  47. begin
  48. Result:=System.SafeLoadLibrary(Name);
  49. end;
  50. Function LoadLibrary(const Name : UnicodeString) : TLibHandle;
  51. begin
  52. Result:=System.LoadLibrary(Name);
  53. end;
  54. Function GetProcedureAddress(Lib : TLibHandle; const ProcName: AnsiString) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif};
  55. begin
  56. Result:=System.GetProcedureAddress(Lib, ProcName);
  57. end;
  58. Function GetProcedureAddress(Lib : TLibHandle; Ordinal : TOrdinalEntry) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif};
  59. begin
  60. Result:=System.GetProcedureAddress(Lib, Ordinal);
  61. end;
  62. Function UnloadLibrary(Lib : TLibHandle) : Boolean;
  63. begin
  64. Result:=System.UnloadLibrary(Lib);
  65. end;
  66. Function GetLoadErrorStr: String;
  67. begin
  68. Result:=System.GetLoadErrorStr;
  69. end;
  70. Function FreeLibrary(Lib : TLibHandle) : Boolean;
  71. begin
  72. Result:=System.FreeLibrary(lib);
  73. end;
  74. Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif};
  75. begin
  76. Result:=System.GetProcedureAddress(Lib,Procname);
  77. end;
  78. initialization
  79. InitDynLibs;
  80. finalization
  81. {$if declared(DoneDynLibs)}
  82. DoneDynLibs;
  83. {$endif}
  84. end.