dynlibs.pas 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. { ---------------------------------------------------------------------
  17. Read OS-dependent interface declarations.
  18. ---------------------------------------------------------------------}
  19. {$define readinterface}
  20. {$i dynlibs.inc}
  21. {$undef readinterface}
  22. { ---------------------------------------------------------------------
  23. OS - Independent declarations.
  24. ---------------------------------------------------------------------}
  25. Function SafeLoadLibrary(Name : AnsiString) : TLibHandle;
  26. Function LoadLibrary(Name : AnsiString) : TLibHandle;
  27. Function GetProcedureAddress(Lib : TlibHandle; ProcName : AnsiString) : Pointer;
  28. Function UnloadLibrary(Lib : TLibHandle) : Boolean;
  29. // Kylix/Delphi compability
  30. Function FreeLibrary(Lib : TLibHandle) : Boolean;
  31. Function GetProcAddress(Lib : TlibHandle; ProcName : AnsiString) : Pointer;
  32. Type
  33. HModule = TLibHandle;
  34. Implementation
  35. { ---------------------------------------------------------------------
  36. OS - Independent declarations.
  37. ---------------------------------------------------------------------}
  38. {$i dynlibs.inc}
  39. Function FreeLibrary(Lib : TLibHandle) : Boolean;
  40. begin
  41. Result:=UnloadLibrary(lib);
  42. end;
  43. Function GetProcAddress(Lib : TlibHandle; ProcName : AnsiString) : Pointer;
  44. begin
  45. Result:=GetProcedureAddress(Lib,Procname);
  46. end;
  47. Function SafeLoadLibrary(Name : AnsiString) : TLibHandle;
  48. {$ifdef i386}
  49. var w : word;
  50. {$endif}
  51. Begin
  52. {$ifdef i386}
  53. w:=get8087cw;
  54. {$endif}
  55. result:=loadlibrary(name);
  56. {$ifdef i386}
  57. set8087cw(w);
  58. {$endif}
  59. End;
  60. end.