dynlibs.inc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // these are for easier crossplatform construction of dll names in dynloading libs.
  21. {$ifdef Darwin}
  22. SharedSuffix = 'dylib';
  23. {$else Darwin}
  24. SharedSuffix = 'so';
  25. {$endif Darwin}
  26. {$else}
  27. { ---------------------------------------------------------------------
  28. Implementation section
  29. ---------------------------------------------------------------------}
  30. uses dl;
  31. Function LoadLibrary(const Name : AnsiString) : TLibHandle;
  32. begin
  33. Result:=TLibHandle(dlopen(Pchar(Name),RTLD_LAZY));
  34. end;
  35. Function GetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
  36. begin
  37. Result:=dlsym(lib,pchar(ProcName));
  38. end;
  39. Function UnloadLibrary(Lib : TLibHandle) : Boolean;
  40. begin
  41. Result:=dlClose(Lib)=0;
  42. end;
  43. {$endif}