dynlibs.inc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. {$define DYNLIBS_SUPPORTS_ORDINAL}
  16. Type
  17. TLibHandle = System.THandle;
  18. TOrdinalEntry = word;
  19. Const
  20. NilHandle = 0;
  21. // these are for easier crossplatform construction of dll names in dynloading libs.
  22. SharedSuffix = 'dll';
  23. {$else}
  24. { ---------------------------------------------------------------------
  25. Implementation section
  26. ---------------------------------------------------------------------}
  27. Uses windows;
  28. Function DoLoadLibrary(const Name : UnicodeString) : TlibHandle;
  29. begin
  30. Result:=Windows.LoadLibraryW(PWideChar(Name));
  31. end;
  32. Function GetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
  33. begin
  34. Result:=Windows.GetProcAddress(Lib,PChar(ProcName));
  35. end;
  36. Function GetProcedureAddress(Lib : TLibHandle; Ordinal : Word) : Pointer;
  37. begin
  38. Result:=Windows.GetProcAddress(Lib,PChar(Ordinal));
  39. end;
  40. Function UnloadLibrary(Lib : TLibHandle) : Boolean;
  41. begin
  42. Result:=Windows.FreeLibrary(Lib);
  43. end;
  44. Function GetLoadErrorStr: string;
  45. Var
  46. rc,c : integer;
  47. begin
  48. rc := GetLastError;
  49. SetLength(Result,255);
  50. C:=FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,nil,rc,
  51. MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
  52. @Result[1], 255,nil);
  53. SetLength(Result,c);
  54. end;
  55. {$endif}