sysdl.inc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. Function SysLoadLibraryU(const Name : UnicodeString) : TlibHandle;
  12. begin
  13. Result:=WinLoadLibraryW(PWideChar(Name));
  14. end;
  15. Function SysLoadLibraryA(const Name: RawByteString) : TLibHandle;
  16. begin
  17. Result:=WinLoadLibraryW(PWideChar(UnicodeString(Name)));
  18. end;
  19. Function SysGetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
  20. begin
  21. Result:=WinGetProcAddress(Lib,PChar(ProcName));
  22. end;
  23. {$push}
  24. {$warn 4056 off}
  25. Function SysGetProcedureAddressOrdinal(Lib : TLibHandle; Ordinal : TOrdinalEntry) : Pointer;
  26. begin
  27. Result:=WinGetProcAddress(Lib,PChar(Ordinal));
  28. end;
  29. {$pop}
  30. Function SysUnloadLibrary(Lib : TLibHandle) : Boolean;
  31. begin
  32. Result:=WinFreeLibrary(Lib);
  33. end;
  34. Function SysGetLoadErrorStr: string;
  35. Var
  36. rc,c : integer;
  37. temp: WideString;
  38. begin
  39. rc := GetLastError;
  40. SetLength(temp,255);
  41. C:=FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,nil,rc,
  42. MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
  43. @temp[1], 255,nil);
  44. SetLength(temp,c);
  45. Result:=AnsiString(temp);
  46. end;
  47. const
  48. SysDynLibsManager: TDynLibsManager = (
  49. LoadLibraryU: @SysLoadLibraryU;
  50. LoadLibraryA: @SysLoadLibraryA;
  51. GetProcAddress: @SysGetProcedureAddress;
  52. GetProcAddressOrdinal: @SysGetProcedureAddressOrdinal;
  53. UnloadLibrary: @SysUnloadLibrary;
  54. GetLoadErrorStr: @SysGetLoadErrorStr;
  55. );
  56. procedure InitSystemDynLibs;
  57. begin
  58. SetDynLibsManager(SysDynLibsManager);
  59. end;