dynlibs.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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
  26. DosCalls;
  27. function LoadLibrary (const Name: AnsiString): TLibHandle;
  28. var
  29. ErrPath: array [0..259] of char;
  30. Handle: longint;
  31. begin
  32. if DosLoadModule (@ErrPath, SizeOf (ErrPath), PChar (Name), Handle) = 0
  33. then Result := Handle else Result := NilHandle;
  34. end;
  35. function GetProcedureAddress (Lib: TLibHandle; const ProcName: AnsiString): pointer;
  36. var
  37. P: pointer;
  38. begin
  39. if DosQueryProcAddr (Lib, 0, PChar (ProcName), P) = 0 then Result := P
  40. else Result := nil;
  41. end;
  42. function UnloadLibrary (Lib: TLibHandle): boolean;
  43. begin
  44. Result := DosFreeModule (Lib) = 0;
  45. end;
  46. {$endif}