dynlibs.inc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2004 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. TLibHandle = Pointer;
  17. Const
  18. NilHandle = Nil;
  19. // these are for easier crossplatform construction of dll names in dynloading libs.
  20. SharedSuffix = 'so';
  21. {$else}
  22. { ---------------------------------------------------------------------
  23. Implementation section
  24. ---------------------------------------------------------------------}
  25. uses libc;
  26. Function LoadLibrary(const Name : AnsiString) : TLibHandle;
  27. begin
  28. Result:=dlopen(Pchar(Name),RTLD_LAZY);
  29. end;
  30. Function GetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
  31. begin
  32. Result:=dlsym(lib,pchar(ProcName));
  33. end;
  34. Function UnloadLibrary(Lib : TLibHandle) : Boolean;
  35. begin
  36. Result:=dlClose(Lib)=0;
  37. end;
  38. {$endif}