sysdl.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. var
  12. LastLoadLibraryError: 0..HINSTANCE_ERROR;
  13. function SysLoadLibraryU(const Name : UnicodeString) : TlibHandle;
  14. begin
  15. Result:=WinLoadLibrary(LPCSTR(AnsiString(Name)));
  16. if Result<=HINSTANCE_ERROR then
  17. begin
  18. LastLoadLibraryError:=Result;
  19. Result:=0;
  20. end;
  21. end;
  22. function SysLoadLibraryA(const Name: RawByteString) : TLibHandle;
  23. begin
  24. Result:=WinLoadLibrary(LPCSTR(Name));
  25. if Result<=HINSTANCE_ERROR then
  26. begin
  27. LastLoadLibraryError:=Result;
  28. Result:=0;
  29. end;
  30. end;
  31. function SysGetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : FarPointer;
  32. begin
  33. Result:=WinGetProcAddress(Lib,LPCSTR(ProcName));
  34. end;
  35. {$push}
  36. {$warn 4056 off}
  37. function SysGetProcedureAddressOrdinal(Lib : TLibHandle; Ordinal : TOrdinalEntry) : FarPointer;
  38. begin
  39. Result:=WinGetProcAddress(Lib,LPCSTR(Ordinal));
  40. end;
  41. {$pop}
  42. function SysUnloadLibrary(Lib : TLibHandle) : Boolean;
  43. begin
  44. WinFreeLibrary(Lib);
  45. Result:=true;
  46. end;
  47. function SysGetLoadErrorStr: ansistring;
  48. var
  49. rc,c : integer;
  50. temp: WideString;
  51. begin
  52. case LastLoadLibraryError of
  53. 0: Result := 'System out of memory, executable file is corrupt, or contains invalid relocations';
  54. 2: Result := 'File not found';
  55. 3: Result := 'Path not found';
  56. 5: Result := 'Attempt was made to dynamically link to a task, or there was a sharing or network-protection error';
  57. 6: Result := 'Library requires separate data segments for each task';
  58. 8: Result := 'Insufficient memory to start the application';
  59. 10: Result := 'Incorrect Windows version';
  60. 11: Result := 'Invalid executable file. Either it is not a Windows application or there is an error in the .EXE image';
  61. 12: Result := 'Application is designed for a different operating system';
  62. 13: Result := 'Application is designed for MS-DOS 4.0';
  63. 14: Result := 'Type of executable is unknown';
  64. 15: Result := 'Cannot load a real-mode application (developed for an earlier version of Windows)';
  65. 16: Result := 'Cannot load a second instance of an executable file containing multiple data segments that are not marked read-only';
  66. 19: Result := 'Cannot load a compressed executable file. The file must be decompressed before it can be loaded';
  67. 20: Result := 'One of the DLLs required to run this application is corrupt';
  68. 21: Result := 'Application requires Microsoft Windows 32-bit extensions';
  69. else
  70. Result := 'Unknown error code';
  71. end;
  72. WriteStr(Result, '(', LastLoadLibraryError, ') - ', Result);
  73. end;
  74. const
  75. SysDynLibsManager: TDynLibsManager = (
  76. LoadLibraryU: @SysLoadLibraryU;
  77. LoadLibraryA: @SysLoadLibraryA;
  78. GetProcAddress: @SysGetProcedureAddress;
  79. GetProcAddressOrdinal: @SysGetProcedureAddressOrdinal;
  80. UnloadLibrary: @SysUnloadLibrary;
  81. GetLoadErrorStr: @SysGetLoadErrorStr;
  82. );
  83. procedure InitSystemDynLibs;
  84. begin
  85. SetDynLibsManager(SysDynLibsManager);
  86. end;