dynlibs.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. {$IFNDEF FPC_DOTTEDUNITS}
  15. unit dynlibs;
  16. {$ENDIF}
  17. interface
  18. Type
  19. TLibHandle = System.TLibHandle;
  20. Const
  21. NilHandle = System.NilHandle;
  22. SharedSuffix = System.SharedSuffix;
  23. Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle; inline;
  24. Function LoadLibrary(const Name : RawByteString) : TLibHandle; inline;
  25. Function SafeLoadLibrary(const Name : UnicodeString) : TLibHandle; inline;
  26. Function LoadLibrary(const Name : UnicodeString) : TLibHandle; inline;
  27. Function GetProcedureAddress(Lib : TlibHandle; const ProcName : AnsiString) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif}; inline;
  28. Function GetProcedureAddress(Lib : TLibHandle; Ordinal: TOrdinalEntry) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif}; inline;
  29. Function UnloadLibrary(Lib : TLibHandle) : Boolean; inline;
  30. Function GetLoadErrorStr: ansistring; inline;
  31. // Kylix/Delphi compability
  32. Function FreeLibrary(Lib : TLibHandle) : Boolean; inline;
  33. Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif}; inline;
  34. Type
  35. HModule = TLibHandle;
  36. Implementation
  37. { Should define a procedure InitDynLibs which sets up the DynLibs manager; optionally a
  38. DoneDynLibs can be defined which is called during finalization }
  39. {$i dynlibs.inc}
  40. Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle;
  41. begin
  42. Result:=System.SafeLoadLibrary(Name);
  43. end;
  44. Function LoadLibrary(const Name : RawByteString) : TLibHandle;
  45. begin
  46. Result:=System.LoadLibrary(Name);
  47. end;
  48. Function SafeLoadLibrary(const Name : UnicodeString) : TLibHandle;
  49. begin
  50. Result:=System.SafeLoadLibrary(Name);
  51. end;
  52. Function LoadLibrary(const Name : UnicodeString) : TLibHandle;
  53. begin
  54. Result:=System.LoadLibrary(Name);
  55. end;
  56. Function GetProcedureAddress(Lib : TLibHandle; const ProcName: AnsiString) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif};
  57. begin
  58. Result:=System.GetProcedureAddress(Lib, ProcName);
  59. end;
  60. Function GetProcedureAddress(Lib : TLibHandle; Ordinal : TOrdinalEntry) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif};
  61. begin
  62. Result:=System.GetProcedureAddress(Lib, Ordinal);
  63. end;
  64. Function UnloadLibrary(Lib : TLibHandle) : Boolean;
  65. begin
  66. Result:=System.UnloadLibrary(Lib);
  67. end;
  68. Function GetLoadErrorStr: AnsiString;
  69. begin
  70. Result:=System.GetLoadErrorStr;
  71. end;
  72. Function FreeLibrary(Lib : TLibHandle) : Boolean;
  73. begin
  74. Result:=System.FreeLibrary(lib);
  75. end;
  76. Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : {$ifdef cpui8086}FarPointer{$else}Pointer{$endif};
  77. begin
  78. Result:=System.GetProcedureAddress(Lib,Procname);
  79. end;
  80. initialization
  81. InitDynLibs;
  82. finalization
  83. {$if declared(DoneDynLibs)}
  84. DoneDynLibs;
  85. {$endif}
  86. end.