dllfuncs.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. {
  2. $Id$
  3. **********************************************************************}
  4. {$MODE OBJFPC}
  5. unit DLLFuncs;
  6. interface
  7. uses SysUtils;
  8. function LoadLibrary(Name: PChar): PtrInt;
  9. function GetProcAddress(Lib: PtrInt; ProcName: PChar): Pointer;
  10. function FreeLibrary(Lib: PtrInt): Boolean;
  11. function getlastdlerror: pchar;
  12. implementation
  13. const
  14. RTLD_LAZY = $001;
  15. RTLD_NOW = $002;
  16. RTLD_BINDING_MASK = $003;
  17. {$ifdef Linux}
  18. function dlopen(Name: PChar; Flags: LongInt) : Pointer; cdecl; external 'dl';
  19. function dlsym(Lib: Pointer; Name: PChar) : Pointer; cdecl; external 'dl';
  20. function dlclose(Lib: Pointer): LongInt; cdecl; external 'dl';
  21. function dlerror: pchar; cdecl; external 'dl';
  22. {$else}
  23. function dlopen(Name: PChar; Flags: LongInt) : Pointer; cdecl; external 'c';
  24. function dlsym(Lib: Pointer; Name: PChar) : Pointer; cdecl; external 'c';
  25. function dlclose(Lib: Pointer): LongInt; cdecl; external 'c';
  26. function dlerror: pchar; cdecl; external 'c';
  27. {$endif}
  28. function getlastdlerror: pchar;
  29. begin
  30. getlastdlerror := dlerror;
  31. end;
  32. function LoadLibrary(Name: PChar): PtrInt;
  33. begin
  34. Result := PtrInt(dlopen(Name, RTLD_LAZY));
  35. end;
  36. function GetProcAddress(Lib: PtrInt; ProcName: PChar): Pointer;
  37. begin
  38. Result := dlsym(Pointer(Lib), ProcName);
  39. end;
  40. function FreeLibrary(Lib: PtrInt): Boolean;
  41. begin
  42. if Lib = 0 then
  43. Result := False
  44. else
  45. Result := dlClose(Pointer(Lib)) = 0;
  46. end;
  47. end.
  48. {
  49. $Log$
  50. Revision 1.4 2004-12-15 21:17:46 peter
  51. * thandle -> ptrint
  52. Revision 1.3 2004/11/24 20:04:09 jonas
  53. + basic Mac OS X support, only bounce works for now though
  54. Revision 1.2 2003/08/25 18:16:38 marco
  55. * BSD fix
  56. Revision 1.1 2002/10/13 13:57:30 sg
  57. * Finally, the new units are available: Match the C headers more closely;
  58. support for OpenGL extensions, and much more. Based on the Delphi units
  59. by Tom Nuydens of delphi3d.net
  60. }