dllfuncs.pp 1.5 KB

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