dllfuncs.pp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. function dlopen(Name: PChar; Flags: LongInt) : Pointer; cdecl; external 'dl';
  17. function dlsym(Lib: Pointer; Name: PChar) : Pointer; cdecl; external 'dl';
  18. function dlclose(Lib: Pointer): LongInt; cdecl; external 'dl';
  19. function LoadLibrary(Name: PChar): THandle;
  20. begin
  21. Result := THandle(dlopen(Name, RTLD_LAZY));
  22. end;
  23. function GetProcAddress(Lib: THandle; ProcName: PChar): Pointer;
  24. begin
  25. Result := dlsym(Pointer(Lib), ProcName);
  26. end;
  27. function FreeLibrary(Lib: THandle): Boolean;
  28. begin
  29. if Lib = 0 then
  30. Result := False
  31. else
  32. Result := dlClose(Pointer(Lib)) = 0;
  33. end;
  34. end.
  35. {
  36. $Log$
  37. Revision 1.1 2002-10-13 13:57:30 sg
  38. * Finally, the new units are available: Match the C headers more closely;
  39. support for OpenGL extensions, and much more. Based on the Delphi units
  40. by Tom Nuydens of delphi3d.net
  41. }