sysutilh.inc 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. member of the Free Pascal development team
  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. { Using inlining for small system functions/wrappers }
  12. {$inline on}
  13. {$define SYSUTILSINLINE}
  14. { Read internationalization settings }
  15. {$i sysinth.inc}
  16. { Read date & Time function declarations }
  17. {$i osutilsh.inc}
  18. {$ifndef FPUNONE}
  19. {$i datih.inc}
  20. {$endif}
  21. function GetTickCount: LongWord; deprecated 'Use GetTickCount64 instead';
  22. function GetTickCount64: QWord;
  23. { Read String Handling functions declaration }
  24. {$i sysstrh.inc}
  25. type
  26. { some helpful data types }
  27. THandle = System.THandle;
  28. TProcedure = procedure;
  29. TFilename = String;
  30. TIntegerSet = Set of 0..SizeOf(Integer)*8-1;
  31. LongRec = packed record
  32. case Integer of
  33. {$ifdef FPC_LITTLE_ENDIAN}
  34. 0 : (Lo,Hi : Word);
  35. {$else FPC_LITTLE_ENDIAN}
  36. 0 : (Hi,Lo : Word);
  37. {$endif FPC_LITTLE_ENDIAN}
  38. 1 : (Bytes : Array[0..3] of Byte);
  39. end;
  40. WordRec = packed record
  41. {$ifdef FPC_LITTLE_ENDIAN}
  42. Lo,Hi : Byte;
  43. {$else FPC_LITTLE_ENDIAN}
  44. Hi,Lo : Byte;
  45. {$endif FPC_LITTLE_ENDIAN}
  46. end;
  47. Int64Rec = packed record
  48. case integer of
  49. {$ifdef FPC_LITTLE_ENDIAN}
  50. 0 : (Lo,Hi : Cardinal);
  51. {$else FPC_LITTLE_ENDIAN}
  52. 0 : (Hi,Lo : Cardinal);
  53. {$endif FPC_LITTLE_ENDIAN}
  54. 1 : (Words : Array[0..3] of Word);
  55. 2 : (Bytes : Array[0..7] of Byte);
  56. end;
  57. Int128Rec = packed record
  58. case integer of
  59. {$ifdef FPC_LITTLE_ENDIAN}
  60. 0 : (Lo,Hi : QWord);
  61. {$else FPC_LITTLE_ENDIAN}
  62. 0 : (Hi,Lo : QWord);
  63. {$endif FPC_LITTLE_ENDIAN}
  64. 1 : (DWords : Array[0..3] of DWord);
  65. 2 : (Words : Array[0..7] of Word);
  66. 3 : (Bytes : Array[0..15] of Byte);
  67. end;
  68. OWordRec = packed record
  69. case integer of
  70. {$ifdef FPC_LITTLE_ENDIAN}
  71. 0 : (Lo,Hi : QWord);
  72. {$else FPC_LITTLE_ENDIAN}
  73. 0 : (Hi,Lo : QWord);
  74. {$endif FPC_LITTLE_ENDIAN}
  75. 1 : (DWords : Array[0..3] of DWord);
  76. 2 : (Words : Array[0..7] of Word);
  77. 3 : (Bytes : Array[0..15] of Byte);
  78. end;
  79. PByteArray = ^TByteArray;
  80. TByteArray = Array[0..{$ifdef CPU16}32766{$else}32767{$endif}] of Byte;
  81. PWordarray = ^TWordArray;
  82. TWordArray = array[0..{$ifdef CPU16}16382{$else}16383{$endif}] of Word;
  83. TBytes = array of Byte;
  84. { exceptions }
  85. Exception = class(TObject)
  86. private
  87. fmessage : string;
  88. fhelpcontext : longint;
  89. public
  90. constructor Create(const msg : string);
  91. constructor CreateFmt(const msg : string; const args : array of const);
  92. constructor CreateRes(ResString: PString);
  93. constructor CreateResFmt(ResString: PString; const Args: array of const);
  94. constructor CreateHelp(const Msg: string; AHelpContext: Integer);
  95. constructor CreateFmtHelp(const Msg: string; const Args: array of const;
  96. AHelpContext: Integer);
  97. constructor CreateResHelp(ResString: PString; AHelpContext: Integer);
  98. constructor CreateResFmtHelp(ResString: PString; const Args: array of const;
  99. AHelpContext: Integer);
  100. { !!!! }
  101. property HelpContext : longint read fhelpcontext write fhelpcontext;
  102. property Message : string read fmessage write fmessage;
  103. end;
  104. ExceptClass = class of Exception;
  105. EExternal = class(Exception)
  106. {$ifdef windows}
  107. { OS-provided exception record is stored on stack and has very limited lifetime.
  108. Therefore store a complete copy. }
  109. private
  110. FExceptionRecord: TExceptionRecord;
  111. function GetExceptionRecord: PExceptionRecord;
  112. public
  113. property ExceptionRecord : PExceptionRecord read GetExceptionRecord;
  114. {$endif windows}
  115. end;
  116. { integer math exceptions }
  117. EInterror = Class(EExternal);
  118. EDivByZero = Class(EIntError);
  119. ERangeError = Class(EIntError);
  120. EIntOverflow = Class(EIntError);
  121. { General math errors }
  122. EMathError = Class(EExternal);
  123. EInvalidOp = Class(EMathError);
  124. EZeroDivide = Class(EMathError);
  125. EOverflow = Class(EMathError);
  126. EUnderflow = Class(EMathError);
  127. { Run-time and I/O Errors }
  128. EInOutError = class(Exception)
  129. public
  130. ErrorCode : Longint;
  131. end;
  132. EHeapMemoryError = class(Exception)
  133. protected
  134. AllowFree : boolean;
  135. public
  136. procedure FreeInstance;override;
  137. end;
  138. EHeapException = EHeapMemoryError;
  139. EExternalException = class(EExternal);
  140. EInvalidPointer = Class(EHeapMemoryError);
  141. EOutOfMemory = Class(EHeapMemoryError);
  142. EInvalidCast = Class(Exception);
  143. EVariantError = Class(Exception)
  144. ErrCode : longint;
  145. Constructor CreateCode(Code : Longint);
  146. end;
  147. EAccessViolation = Class(EExternal);
  148. EBusError = Class(EAccessViolation);
  149. EPrivilege = class(EExternal);
  150. EStackOverflow = class(EExternal);
  151. EControlC = class(EExternal);
  152. { String conversion errors }
  153. EConvertError = class(Exception);
  154. EFormatError = class(Exception);
  155. { Other errors }
  156. EAbort = Class(Exception);
  157. EAbstractError = Class(Exception);
  158. EAssertionFailed = Class(Exception);
  159. EObjectCheck = Class(Exception);
  160. EPropReadOnly = class(Exception);
  161. EPropWriteOnly = class(Exception);
  162. EIntfCastError = class(Exception);
  163. EInvalidContainer = class(Exception);
  164. EInvalidInsert = class(Exception);
  165. EPackageError = class(Exception);
  166. EOSError = class(Exception)
  167. public
  168. ErrorCode: Longint;
  169. end;
  170. ESafecallException = class(Exception);
  171. ENoThreadSupport = Class(Exception);
  172. ENoWideStringSupport = Class(Exception);
  173. ENotImplemented = class(Exception);
  174. EArgumentException = class(Exception);
  175. EArgumentOutOfRangeException = class(EArgumentException);
  176. ENoConstructException = class(Exception);
  177. { Exception handling routines }
  178. function ExceptObject: TObject;
  179. function ExceptAddr: Pointer;
  180. function ExceptFrameCount: Longint;
  181. function ExceptFrames: PPointer;
  182. function ExceptionErrorMessage(ExceptObject: TObject; ExceptAddr: Pointer;
  183. Buffer: PChar; Size: Integer): Integer;
  184. procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
  185. procedure Abort;
  186. procedure OutOfMemoryError;
  187. Type
  188. TBeepHandler = Procedure;
  189. Var
  190. OnBeep : TBeephandler = Nil;
  191. procedure Beep;
  192. function SysErrorMessage(ErrorCode: Integer): String;
  193. Type
  194. TCreateGUIDFunc = Function(Out GUID : TGUID) : Integer;
  195. Var
  196. OnCreateGUID : TCreateGUIDFunc = Nil;
  197. Function CreateGUID(out GUID : TGUID) : Integer;
  198. type
  199. TTerminateProc = Function: Boolean;
  200. procedure AddTerminateProc(TermProc: TTerminateProc);
  201. function CallTerminateProcs: Boolean;
  202. Var
  203. OnShowException : Procedure (Msg : ShortString);
  204. { FileRec/TextRec }
  205. {$i filerec.inc}
  206. {$i textrec.inc}
  207. Const
  208. HexDisplayPrefix : string = '$';
  209. const
  210. // commenting is VP fix. These idents are in a different unit there.
  211. PathDelim={System.}DirectorySeparator;
  212. DriveDelim={System.}DriveSeparator;
  213. PathSep={System.}PathSeparator;
  214. MAX_PATH={System.}MaxPathLen;
  215. Type
  216. TFileRec=FileRec;
  217. TTextRec=TextRec;
  218. { Read pchar handling functions declaration }
  219. {$i syspchh.inc}
  220. { MCBS functions }
  221. {$i sysansih.inc}
  222. {$i syscodepagesh.inc}
  223. { wide string functions }
  224. {$i syswideh.inc}
  225. {$ifdef FPC_HAS_UNICODESTRING}
  226. { unicode string functions }
  227. {$i sysunih.inc}
  228. {$i sysencodingh.inc}
  229. {$endif FPC_HAS_UNICODESTRING}
  230. {$macro on}
  231. {$define PathStr:=UnicodeString}
  232. {$define PathPChar:=PWideChar}
  233. { Read filename handling functions declaration }
  234. {$i finah.inc}
  235. {$define PathStr:=AnsiString}
  236. {$define PathPChar:=PAnsiChar}
  237. { Read filename handling functions declaration }
  238. {$i finah.inc}
  239. {$undef PathStr}
  240. {$undef PathPChar}
  241. { Read other file handling function declarations }
  242. {$i filutilh.inc}
  243. { Read disk function declarations }
  244. {$i diskh.inc}
  245. { read thread handling }
  246. {$i systhrdh.inc}
  247. procedure FreeAndNil(var obj);
  248. { interface handling }
  249. {$i intfh.inc}
  250. function SafeLoadLibrary(const FileName: AnsiString;
  251. ErrorMode: DWord = {$ifdef windows}SEM_NOOPENFILEERRORBOX{$else windows}0{$endif windows}): HMODULE;
  252. function GetModuleName(Module: HMODULE): string;
  253. { some packages and unit related constants for compatibility }
  254. const
  255. pfExeModule = $00000000;
  256. pfNeverBuild = $00000001;
  257. pfDesignOnly = $00000002;
  258. pfRunOnly = $00000004;
  259. pfIgnoreDupUnits = $00000008;
  260. pfPackageModule = $40000000;
  261. pfModuleTypeMask = $C0000000;
  262. pfV3Produced = $00000000;
  263. pfProducerUndefined = $04000000;
  264. pfBCB4Produced = $08000000;
  265. pfDelphi4Produced = $0C000000;
  266. pfLibraryModule = $80000000;
  267. pfProducerMask = $0C000000;
  268. const
  269. ufMainUnit = $01;
  270. ufPackageUnit = $02;
  271. ufWeakUnit = $04;
  272. ufOrgWeakUnit = $08;
  273. ufImplicitUnit = $10;
  274. ufWeakPackageUnit = ufPackageUnit or ufWeakUnit;