dynlibs.inc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. Implement OS-dependent part of dynamic library loading.
  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 readinterface}
  12. { ---------------------------------------------------------------------
  13. Interface declarations
  14. ---------------------------------------------------------------------}
  15. Type
  16. { using PtrInt here is compliant with the other platforms }
  17. TLibHandle = PtrInt;
  18. Const
  19. NilHandle = TLibHandle(0);
  20. {$else}
  21. { ---------------------------------------------------------------------
  22. Implementation section
  23. ---------------------------------------------------------------------}
  24. uses dl;
  25. Function LoadLibrary(Name : AnsiString) : TLibHandle;
  26. begin
  27. Result:=TLibHandle(dlopen(Pchar(Name),RTLD_LAZY));
  28. end;
  29. Function GetProcedureAddress(Lib : TLibHandle; ProcName : AnsiString) : Pointer;
  30. begin
  31. Result:=dlsym(lib,pchar(ProcName));
  32. end;
  33. Function UnloadLibrary(Lib : TLibHandle) : Boolean;
  34. begin
  35. Result:=dlClose(Lib)=0;
  36. end;
  37. {$endif}