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. Implements OS dependent part for loading of dynamic libraries.
  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 = Longint;
  17. Const
  18. NilHandle = 0;
  19. // these are for easier crossplatform construction of dll names in dynloading libs.
  20. SharedSuffix = 'dll';
  21. {$else}
  22. { ---------------------------------------------------------------------
  23. Implementation section
  24. ---------------------------------------------------------------------}
  25. Uses windows;
  26. Function LoadLibrary(Name : AnsiString) : TlibHandle;
  27. var
  28. ws: PWideChar;
  29. begin
  30. ws:=StringToPWideChar(Name);
  31. Result:=Windows.LoadLibrary(ws);
  32. FreeMem(ws);
  33. end;
  34. Function GetProcedureAddress(Lib : TLibHandle; ProcName : AnsiString) : Pointer;
  35. var
  36. ws: PWideChar;
  37. begin
  38. ws:=StringToPWideChar(ProcName);
  39. Result:=Windows.GetProcAddress(Lib, ws);
  40. FreeMem(ws);
  41. end;
  42. Function UnloadLibrary(Lib : TLibHandle) : Boolean;
  43. begin
  44. Result:=Windows.FreeLibrary(Lib);
  45. end;
  46. {$endif}