sysutils.pp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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. Sysutils unit for win32
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit sysutils;
  13. interface
  14. {$MODE objfpc}
  15. { force ansistrings }
  16. {$H+}
  17. uses
  18. windows;
  19. {$DEFINE HAS_SLEEP}
  20. {$DEFINE HAS_OSERROR}
  21. {$DEFINE HAS_OSCONFIG}
  22. {$DEFINE HAS_OSUSERDIR}
  23. {$DEFINE HAS_CREATEGUID}
  24. { Include platform independent interface part }
  25. {$i sysutilh.inc}
  26. type
  27. TSystemTime = Windows.TSystemTime;
  28. EWin32Error = class(Exception)
  29. public
  30. ErrorCode : DWORD;
  31. end;
  32. Var
  33. Win32Platform : Longint;
  34. Win32MajorVersion,
  35. Win32MinorVersion,
  36. Win32BuildNumber : dword;
  37. Win32CSDVersion : ShortString; // CSD record is 128 bytes only?
  38. { Compatibility with Delphi }
  39. function Win32Check(res:boolean):boolean;inline;
  40. function WinCheck(res:boolean):boolean;
  41. function CheckWin32Version(Major,Minor : Integer ): Boolean;
  42. function CheckWin32Version(Major : Integer): Boolean;
  43. Procedure RaiseLastWin32Error;
  44. function GetFileVersion(const AFileName: string): Cardinal;
  45. procedure GetFormatSettings;
  46. implementation
  47. uses
  48. sysconst;
  49. function WinCheck(res:boolean):boolean;
  50. begin
  51. if not res then
  52. RaiseLastOSError;
  53. result:=res;
  54. end;
  55. function Win32Check(res:boolean):boolean;inline;
  56. begin
  57. result:=WinCheck(res);
  58. end;
  59. procedure RaiseLastWin32Error;
  60. begin
  61. RaiseLastOSError;
  62. end;
  63. function CheckWin32Version(Major : Integer): Boolean;
  64. begin
  65. Result:=CheckWin32Version(Major,0)
  66. end;
  67. function CheckWin32Version(Major,Minor: Integer): Boolean;
  68. begin
  69. Result:=(Win32MajorVersion>dword(Major)) or
  70. ((Win32MajorVersion=dword(Major)) and (Win32MinorVersion>=dword(Minor)));
  71. end;
  72. function GetFileVersion(const AFileName:string):Cardinal;
  73. var
  74. { usefull only as long as we don't need to touch different stack pages }
  75. buf : array[0..3071] of byte;
  76. bufp : pointer;
  77. fn : string;
  78. valsize,
  79. size : DWORD;
  80. h : DWORD;
  81. valrec : PVSFixedFileInfo;
  82. begin
  83. result:=$fffffff;
  84. fn:=AFileName;
  85. UniqueString(fn);
  86. size:=GetFileVersionInfoSize(pchar(fn),@h);
  87. if size>sizeof(buf) then
  88. begin
  89. getmem(bufp,size);
  90. try
  91. if GetFileVersionInfo(pchar(fn),h,size,bufp) then
  92. if VerQueryValue(bufp,'\',valrec,valsize) then
  93. result:=valrec^.dwFileVersionMS;
  94. finally
  95. freemem(bufp);
  96. end;
  97. end
  98. else
  99. begin
  100. if GetFileVersionInfo(pchar(fn),h,size,@buf) then
  101. if VerQueryValue(@buf,'\',valrec,valsize) then
  102. result:=valrec^.dwFileVersionMS;
  103. end;
  104. end;
  105. {$define HASCREATEGUID}
  106. {$define HASEXPANDUNCFILENAME}
  107. {$DEFINE FPC_NOGENERICANSIROUTINES}
  108. {$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
  109. {$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
  110. { Include platform independent implementation part }
  111. {$i sysutils.inc}
  112. function SysGetTempFileName(lpPathName:LPCSTR;
  113. lpPrefixString:LPCSTR;
  114. uUnique:UINT;
  115. lpTempFileName:LPSTR):UINT;stdcall;external 'kernel32' name 'GetTempFileNameA';
  116. function GetTempFileName(Dir,Prefix: PChar; uUnique: DWORD; TempFileName: PChar):DWORD;
  117. begin
  118. Result:=SysGetTempFileName(Dir,Prefix,uUnique,TempFileName);
  119. end;
  120. { UUID generation. }
  121. function CoCreateGuid(out guid: TGUID): HResult; stdcall; external 'ole32.dll' name 'CoCreateGuid';
  122. function SysCreateGUID(out Guid: TGUID): Integer;
  123. begin
  124. Result := Integer(CoCreateGuid(Guid));
  125. end;
  126. function ExpandUNCFileName (const filename:string) : string;
  127. { returns empty string on errors }
  128. var
  129. s : ansistring;
  130. size : dword;
  131. rc : dword;
  132. buf : pchar;
  133. begin
  134. s := ExpandFileName (filename);
  135. s := s + #0;
  136. size := max_path;
  137. getmem(buf,size);
  138. try
  139. rc := WNetGetUniversalName (pchar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
  140. if rc=ERROR_MORE_DATA then
  141. begin
  142. buf:=reallocmem(buf,size);
  143. rc := WNetGetUniversalName (pchar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
  144. end;
  145. if rc = NO_ERROR then
  146. Result := PRemoteNameInfo(buf)^.lpUniversalName
  147. else if rc = ERROR_NOT_CONNECTED then
  148. Result := filename
  149. else
  150. Result := '';
  151. finally
  152. freemem(buf);
  153. end;
  154. end;
  155. {****************************************************************************
  156. File Functions
  157. ****************************************************************************}
  158. var
  159. SetFilePointerEx : function(hFile : THandle;
  160. liDistanceToMove : int64;lpNewFilePointer : pint64;
  161. dwMoveMethod : DWord) : ByteBool;stdcall;
  162. Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
  163. const
  164. AccessMode: array[0..2] of Cardinal = (
  165. GENERIC_READ,
  166. GENERIC_WRITE,
  167. GENERIC_READ or GENERIC_WRITE);
  168. ShareMode: array[0..4] of Integer = (
  169. 0,
  170. 0,
  171. FILE_SHARE_READ,
  172. FILE_SHARE_WRITE,
  173. FILE_SHARE_READ or FILE_SHARE_WRITE);
  174. Var
  175. FN : string;
  176. begin
  177. FN:=FileName+#0;
  178. result := CreateFile(@FN[1], dword(AccessMode[Mode and 3]),
  179. dword(ShareMode[(Mode and $F0) shr 4]), nil, OPEN_EXISTING,
  180. FILE_ATTRIBUTE_NORMAL, 0);
  181. //if fail api return feInvalidHandle (INVALIDE_HANDLE=feInvalidHandle=-1)
  182. end;
  183. Function FileCreate (Const FileName : String) : THandle;
  184. Var
  185. FN : string;
  186. begin
  187. FN:=FileName+#0;
  188. Result := CreateFile(@FN[1], GENERIC_READ or GENERIC_WRITE,
  189. 0, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  190. end;
  191. Function FileCreate (Const FileName : String; Mode:longint) : THandle;
  192. begin
  193. FileCreate:=FileCreate(FileName);
  194. end;
  195. Function FileRead (Handle : THandle; Var Buffer; Count : longint) : Longint;
  196. Var
  197. res : dword;
  198. begin
  199. if ReadFile(Handle, Buffer, Count, res, nil) then
  200. FileRead:=Res
  201. else
  202. FileRead:=-1;
  203. end;
  204. Function FileWrite (Handle : THandle; const Buffer; Count : Longint) : Longint;
  205. Var
  206. Res : dword;
  207. begin
  208. if WriteFile(Handle, Buffer, Count, Res, nil) then
  209. FileWrite:=Res
  210. else
  211. FileWrite:=-1;
  212. end;
  213. Function FileSeek (Handle : THandle;FOffset,Origin : Longint) : Longint;
  214. begin
  215. Result := longint(SetFilePointer(Handle, FOffset, nil, Origin));
  216. end;
  217. Function FileSeek (Handle : THandle; FOffset: Int64; Origin: Longint) : Int64;
  218. var
  219. rslt: Int64Rec;
  220. begin
  221. rslt := Int64Rec(FOffset);
  222. rslt.lo := SetFilePointer(Handle, rslt.lo, @rslt.hi, Origin);
  223. if (rslt.lo = $FFFFFFFF) and (GetLastError <> 0) then
  224. rslt.hi := $FFFFFFFF;
  225. Result := Int64(rslt);
  226. end;
  227. Procedure FileClose (Handle : THandle);
  228. begin
  229. if Handle<=4 then
  230. exit;
  231. CloseHandle(Handle);
  232. end;
  233. Function FileTruncate (Handle : THandle;Size: Int64) : boolean;
  234. begin
  235. {
  236. Result:=longint(SetFilePointer(handle,Size,nil,FILE_BEGIN))<>-1;
  237. }
  238. if FileSeek (Handle, Size, FILE_BEGIN) = Size then
  239. Result:=SetEndOfFile(handle)
  240. else
  241. Result := false;
  242. end;
  243. Function DosToWinTime (DTime:longint;Var Wtime : TFileTime):longbool;
  244. var
  245. lft : TFileTime;
  246. begin
  247. DosToWinTime:=DosDateTimeToFileTime(longrec(dtime).hi,longrec(dtime).lo,@lft) and
  248. LocalFileTimeToFileTime(lft,Wtime);
  249. end;
  250. Function WinToDosTime (Var Wtime : TFileTime;var DTime:longint):longbool;
  251. var
  252. lft : TFileTime;
  253. begin
  254. WinToDosTime:=FileTimeToLocalFileTime(WTime,lft) and
  255. FileTimeToDosDateTime(lft,Longrec(Dtime).Hi,LongRec(DTIME).lo);
  256. end;
  257. Function FileAge (Const FileName : String): Longint;
  258. var
  259. Handle: THandle;
  260. FindData: TWin32FindData;
  261. begin
  262. Handle := FindFirstFile(Pchar(FileName), FindData);
  263. if Handle <> INVALID_HANDLE_VALUE then
  264. begin
  265. Windows.FindClose(Handle);
  266. if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
  267. If WinToDosTime(FindData.ftLastWriteTime,Result) then
  268. exit;
  269. end;
  270. Result := -1;
  271. end;
  272. Function FileExists (Const FileName : String) : Boolean;
  273. var
  274. Attr:Dword;
  275. begin
  276. Attr:=GetFileAttributes(PChar(FileName));
  277. if Attr <> $ffffffff then
  278. Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0
  279. else
  280. Result:=False;
  281. end;
  282. Function DirectoryExists (Const Directory : String) : Boolean;
  283. var
  284. Attr:Dword;
  285. begin
  286. Attr:=GetFileAttributes(PChar(Directory));
  287. if Attr <> $ffffffff then
  288. Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) > 0
  289. else
  290. Result:=False;
  291. end;
  292. Function FindMatch(var f: TSearchRec) : Longint;
  293. begin
  294. { Find file with correct attribute }
  295. While (F.FindData.dwFileAttributes and cardinal(F.ExcludeAttr))<>0 do
  296. begin
  297. if not FindNextFile (F.FindHandle,F.FindData) then
  298. begin
  299. Result:=GetLastError;
  300. exit;
  301. end;
  302. end;
  303. { Convert some attributes back }
  304. WinToDosTime(F.FindData.ftLastWriteTime,F.Time);
  305. f.size:=F.FindData.NFileSizeLow+(qword(maxdword)+1)*F.FindData.NFileSizeHigh;
  306. f.attr:=F.FindData.dwFileAttributes;
  307. f.Name:=StrPas(@F.FindData.cFileName[0]);
  308. Result:=0;
  309. end;
  310. Function FindFirst (Const Path : String; Attr : Longint; out Rslt : TSearchRec) : Longint;
  311. begin
  312. Rslt.Name:=Path;
  313. Rslt.Attr:=attr;
  314. Rslt.ExcludeAttr:=(not Attr) and ($1e);
  315. { $1e = faHidden or faSysFile or faVolumeID or faDirectory }
  316. { FindFirstFile is a Win32 Call }
  317. Rslt.FindHandle:=FindFirstFile (PChar(Path),Rslt.FindData);
  318. If Rslt.FindHandle=Invalid_Handle_value then
  319. begin
  320. Result:=GetLastError;
  321. exit;
  322. end;
  323. { Find file with correct attribute }
  324. Result:=FindMatch(Rslt);
  325. end;
  326. Function FindNext (Var Rslt : TSearchRec) : Longint;
  327. begin
  328. if FindNextFile(Rslt.FindHandle, Rslt.FindData) then
  329. Result := FindMatch(Rslt)
  330. else
  331. Result := GetLastError;
  332. end;
  333. Procedure FindClose (Var F : TSearchrec);
  334. begin
  335. if F.FindHandle <> INVALID_HANDLE_VALUE then
  336. Windows.FindClose(F.FindHandle);
  337. end;
  338. Function FileGetDate (Handle : THandle) : Longint;
  339. Var
  340. FT : TFileTime;
  341. begin
  342. If GetFileTime(Handle,nil,nil,@ft) and
  343. WinToDosTime(FT,Result) then
  344. exit;
  345. Result:=-1;
  346. end;
  347. Function FileSetDate (Handle : THandle;Age : Longint) : Longint;
  348. Var
  349. FT: TFileTime;
  350. begin
  351. Result := 0;
  352. if DosToWinTime(Age,FT) and
  353. SetFileTime(Handle, nil, nil, @FT) then
  354. Exit;
  355. Result := GetLastError;
  356. end;
  357. Function FileGetAttr (Const FileName : String) : Longint;
  358. begin
  359. Result:=GetFileAttributes(PChar(FileName));
  360. end;
  361. Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
  362. begin
  363. if SetFileAttributes(PChar(FileName), Attr) then
  364. Result:=0
  365. else
  366. Result := GetLastError;
  367. end;
  368. Function DeleteFile (Const FileName : String) : Boolean;
  369. begin
  370. Result:=Windows.DeleteFile(Pchar(FileName));
  371. end;
  372. Function RenameFile (Const OldName, NewName : String) : Boolean;
  373. begin
  374. Result := MoveFile(PChar(OldName), PChar(NewName));
  375. end;
  376. {****************************************************************************
  377. Disk Functions
  378. ****************************************************************************}
  379. function GetDiskFreeSpace(drive:pchar;var sector_cluster,bytes_sector,
  380. freeclusters,totalclusters:longint):longbool;
  381. stdcall;external 'kernel32' name 'GetDiskFreeSpaceA';
  382. type
  383. TGetDiskFreeSpaceEx = function(drive:pchar;var availableforcaller,total,free):longbool;stdcall;
  384. var
  385. GetDiskFreeSpaceEx : TGetDiskFreeSpaceEx;
  386. function diskfree(drive : byte) : int64;
  387. var
  388. disk : array[1..4] of char;
  389. secs,bytes,
  390. free,total : longint;
  391. qwtotal,qwfree,qwcaller : int64;
  392. begin
  393. if drive=0 then
  394. begin
  395. disk[1]:='\';
  396. disk[2]:=#0;
  397. end
  398. else
  399. begin
  400. disk[1]:=chr(drive+64);
  401. disk[2]:=':';
  402. disk[3]:='\';
  403. disk[4]:=#0;
  404. end;
  405. if assigned(GetDiskFreeSpaceEx) then
  406. begin
  407. if GetDiskFreeSpaceEx(@disk[1],qwcaller,qwtotal,qwfree) then
  408. diskfree:=qwfree
  409. else
  410. diskfree:=-1;
  411. end
  412. else
  413. begin
  414. if GetDiskFreeSpace(@disk[1],secs,bytes,free,total) then
  415. diskfree:=int64(free)*secs*bytes
  416. else
  417. diskfree:=-1;
  418. end;
  419. end;
  420. function disksize(drive : byte) : int64;
  421. var
  422. disk : array[1..4] of char;
  423. secs,bytes,
  424. free,total : longint;
  425. qwtotal,qwfree,qwcaller : int64;
  426. begin
  427. if drive=0 then
  428. begin
  429. disk[1]:='\';
  430. disk[2]:=#0;
  431. end
  432. else
  433. begin
  434. disk[1]:=chr(drive+64);
  435. disk[2]:=':';
  436. disk[3]:='\';
  437. disk[4]:=#0;
  438. end;
  439. if assigned(GetDiskFreeSpaceEx) then
  440. begin
  441. if GetDiskFreeSpaceEx(@disk[1],qwcaller,qwtotal,qwfree) then
  442. disksize:=qwtotal
  443. else
  444. disksize:=-1;
  445. end
  446. else
  447. begin
  448. if GetDiskFreeSpace(@disk[1],secs,bytes,free,total) then
  449. disksize:=int64(total)*secs*bytes
  450. else
  451. disksize:=-1;
  452. end;
  453. end;
  454. Function GetCurrentDir : String;
  455. begin
  456. GetDir(0, result);
  457. end;
  458. Function SetCurrentDir (Const NewDir : String) : Boolean;
  459. begin
  460. Result:=SetCurrentDirectory(PChar(NewDir));
  461. end;
  462. Function CreateDir (Const NewDir : String) : Boolean;
  463. begin
  464. Result:=CreateDirectory(PChar(NewDir),nil);
  465. end;
  466. Function RemoveDir (Const Dir : String) : Boolean;
  467. begin
  468. Result:=RemoveDirectory(PChar(Dir));
  469. end;
  470. {****************************************************************************
  471. Time Functions
  472. ****************************************************************************}
  473. Procedure GetLocalTime(var SystemTime: TSystemTime);
  474. Var
  475. Syst : Windows.TSystemtime;
  476. begin
  477. windows.Getlocaltime(@syst);
  478. SystemTime.year:=syst.wYear;
  479. SystemTime.month:=syst.wMonth;
  480. SystemTime.day:=syst.wDay;
  481. SystemTime.hour:=syst.wHour;
  482. SystemTime.minute:=syst.wMinute;
  483. SystemTime.second:=syst.wSecond;
  484. SystemTime.millisecond:=syst.wMilliSeconds;
  485. end;
  486. {****************************************************************************
  487. Misc Functions
  488. ****************************************************************************}
  489. procedure Beep;
  490. begin
  491. MessageBeep(0);
  492. end;
  493. {****************************************************************************
  494. Locale Functions
  495. ****************************************************************************}
  496. function GetLocaleStr(LID, LT: Longint; const Def: string): ShortString;
  497. var
  498. L: Integer;
  499. Buf: array[0..255] of Char;
  500. begin
  501. L := GetLocaleInfo(LID, LT, Buf, SizeOf(Buf));
  502. if L > 0 then
  503. SetString(Result, @Buf[0], L - 1)
  504. else
  505. Result := Def;
  506. end;
  507. function GetLocaleChar(LID, LT: Longint; Def: Char): Char;
  508. var
  509. Buf: array[0..1] of Char;
  510. begin
  511. if GetLocaleInfo(LID, LT, Buf, 2) > 0 then
  512. Result := Buf[0]
  513. else
  514. Result := Def;
  515. end;
  516. Function GetLocaleInt(LID,TP,Def: LongInt): LongInt;
  517. Var
  518. S: String;
  519. C: Integer;
  520. Begin
  521. S:=GetLocaleStr(LID,TP,'0');
  522. Val(S,Result,C);
  523. If C<>0 Then
  524. Result:=Def;
  525. End;
  526. procedure GetFormatSettings;
  527. var
  528. HF : Shortstring;
  529. LID : LCID;
  530. I,Day : longint;
  531. begin
  532. LID := GetThreadLocale;
  533. { Date stuff }
  534. for I := 1 to 12 do
  535. begin
  536. ShortMonthNames[I]:=GetLocaleStr(LID,LOCALE_SABBREVMONTHNAME1+I-1,ShortMonthNames[i]);
  537. LongMonthNames[I]:=GetLocaleStr(LID,LOCALE_SMONTHNAME1+I-1,LongMonthNames[i]);
  538. end;
  539. for I := 1 to 7 do
  540. begin
  541. Day := (I + 5) mod 7;
  542. ShortDayNames[I]:=GetLocaleStr(LID,LOCALE_SABBREVDAYNAME1+Day,ShortDayNames[i]);
  543. LongDayNames[I]:=GetLocaleStr(LID,LOCALE_SDAYNAME1+Day,LongDayNames[i]);
  544. end;
  545. DateSeparator := GetLocaleChar(LID, LOCALE_SDATE, '/');
  546. ShortDateFormat := GetLocaleStr(LID, LOCALE_SSHORTDATE, 'm/d/yy');
  547. LongDateFormat := GetLocaleStr(LID, LOCALE_SLONGDATE, 'mmmm d, yyyy');
  548. { Time stuff }
  549. TimeSeparator := GetLocaleChar(LID, LOCALE_STIME, ':');
  550. TimeAMString := GetLocaleStr(LID, LOCALE_S1159, 'AM');
  551. TimePMString := GetLocaleStr(LID, LOCALE_S2359, 'PM');
  552. if StrToIntDef(GetLocaleStr(LID, LOCALE_ITLZERO, '0'), 0) = 0 then
  553. HF:='h'
  554. else
  555. HF:='hh';
  556. // No support for 12 hour stuff at the moment...
  557. ShortTimeFormat := HF+':nn';
  558. LongTimeFormat := HF + ':nn:ss';
  559. { Currency stuff }
  560. CurrencyString:=GetLocaleStr(LID, LOCALE_SCURRENCY, '');
  561. CurrencyFormat:=StrToIntDef(GetLocaleStr(LID, LOCALE_ICURRENCY, '0'), 0);
  562. NegCurrFormat:=StrToIntDef(GetLocaleStr(LID, LOCALE_INEGCURR, '0'), 0);
  563. { Number stuff }
  564. ThousandSeparator:=GetLocaleChar(LID, LOCALE_STHOUSAND, ',');
  565. DecimalSeparator:=GetLocaleChar(LID, LOCALE_SDECIMAL, '.');
  566. CurrencyDecimals:=StrToIntDef(GetLocaleStr(LID, LOCALE_ICURRDIGITS, '0'), 0);
  567. end;
  568. Procedure InitInternational;
  569. var
  570. { A call to GetSystemMetrics changes the value of the 8087 Control Word on
  571. Pentium4 with WinXP SP2 }
  572. old8087CW: word;
  573. DefaultCustomLocaleID : LCID; // typedef DWORD LCID;
  574. DefaultCustomLanguageID : Word; // typedef WORD LANGID;
  575. begin
  576. InitInternationalGeneric;
  577. old8087CW:=Get8087CW;
  578. SysLocale.MBCS:=GetSystemMetrics(SM_DBCSENABLED)<>0;
  579. SysLocale.RightToLeft:=GetSystemMetrics(SM_MIDEASTENABLED)<>0;
  580. SysLocale.DefaultLCID := $0409;
  581. SysLocale.PriLangID := LANG_ENGLISH;
  582. SysLocale.SubLangID := SUBLANG_ENGLISH_US;
  583. // probably needs update with getthreadlocale. post 2.0.2
  584. DefaultCustomLocaleID := GetThreadLocale;
  585. if DefaultCustomLocaleID <> 0 then
  586. begin
  587. { Locale Identifiers
  588. +-------------+---------+-------------------------+
  589. | Reserved | Sort ID | Language ID |
  590. +-------------+---------+-------------------------+
  591. 31 20 19 16 15 0 bit }
  592. DefaultCustomLanguageID := DefaultCustomLocaleID and $FFFF; // 2^16
  593. if DefaultCustomLanguageID <> 0 then
  594. begin
  595. SysLocale.DefaultLCID := DefaultCustomLocaleID;
  596. { Language Identifiers
  597. +-------------------------+-------------------------+
  598. | SubLanguage ID | Primary Language ID |
  599. +-------------------------+-------------------------+
  600. 15 10 9 0 bit }
  601. SysLocale.PriLangID := DefaultCustomLanguageID and $3ff; // 2^10
  602. SysLocale.SubLangID := DefaultCustomLanguageID shr 10;
  603. end;
  604. end;
  605. Set8087CW(old8087CW);
  606. GetFormatSettings;
  607. end;
  608. {****************************************************************************
  609. Target Dependent
  610. ****************************************************************************}
  611. function FormatMessageA(dwFlags : DWORD;
  612. lpSource : Pointer;
  613. dwMessageId : DWORD;
  614. dwLanguageId: DWORD;
  615. lpBuffer : PCHAR;
  616. nSize : DWORD;
  617. Arguments : Pointer): DWORD; stdcall;external 'kernel32' name 'FormatMessageA';
  618. function SysErrorMessage(ErrorCode: Integer): String;
  619. const
  620. MaxMsgSize = Format_Message_Max_Width_Mask;
  621. var
  622. MsgBuffer: pChar;
  623. begin
  624. GetMem(MsgBuffer, MaxMsgSize);
  625. FillChar(MsgBuffer^, MaxMsgSize, #0);
  626. FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
  627. nil,
  628. ErrorCode,
  629. MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
  630. MsgBuffer, { This function allocs the memory }
  631. MaxMsgSize, { Maximum message size }
  632. nil);
  633. SysErrorMessage := StrPas(MsgBuffer);
  634. FreeMem(MsgBuffer, MaxMsgSize);
  635. end;
  636. {****************************************************************************
  637. Initialization code
  638. ****************************************************************************}
  639. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  640. var
  641. s : string;
  642. i : longint;
  643. hp,p : pchar;
  644. begin
  645. Result:='';
  646. p:=GetEnvironmentStrings;
  647. hp:=p;
  648. while hp^<>#0 do
  649. begin
  650. s:=strpas(hp);
  651. i:=pos('=',s);
  652. if uppercase(copy(s,1,i-1))=upcase(envvar) then
  653. begin
  654. Result:=copy(s,i+1,length(s)-i);
  655. break;
  656. end;
  657. { next string entry}
  658. hp:=hp+strlen(hp)+1;
  659. end;
  660. FreeEnvironmentStrings(p);
  661. end;
  662. Function GetEnvironmentVariableCount : Integer;
  663. var
  664. hp,p : pchar;
  665. begin
  666. Result:=0;
  667. p:=GetEnvironmentStrings;
  668. hp:=p;
  669. If (Hp<>Nil) then
  670. while hp^<>#0 do
  671. begin
  672. Inc(Result);
  673. hp:=hp+strlen(hp)+1;
  674. end;
  675. FreeEnvironmentStrings(p);
  676. end;
  677. Function GetEnvironmentString(Index : Integer) : String;
  678. var
  679. hp,p : pchar;
  680. begin
  681. Result:='';
  682. p:=GetEnvironmentStrings;
  683. hp:=p;
  684. If (Hp<>Nil) then
  685. begin
  686. while (hp^<>#0) and (Index>1) do
  687. begin
  688. Dec(Index);
  689. hp:=hp+strlen(hp)+1;
  690. end;
  691. If (hp^<>#0) then
  692. Result:=StrPas(HP);
  693. end;
  694. FreeEnvironmentStrings(p);
  695. end;
  696. function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString):integer;
  697. var
  698. SI: TStartupInfo;
  699. PI: TProcessInformation;
  700. Proc : THandle;
  701. l : DWord;
  702. CommandLine : ansistring;
  703. e : EOSError;
  704. begin
  705. FillChar(SI, SizeOf(SI), 0);
  706. SI.cb:=SizeOf(SI);
  707. SI.wShowWindow:=1;
  708. { always surround the name of the application by quotes
  709. so that long filenames will always be accepted. But don't
  710. do it if there are already double quotes, since Win32 does not
  711. like double quotes which are duplicated!
  712. }
  713. if pos('"',path)=0 then
  714. CommandLine:='"'+path+'"'
  715. else
  716. CommandLine:=path;
  717. if ComLine <> '' then
  718. CommandLine:=Commandline+' '+ComLine+#0
  719. else
  720. CommandLine := CommandLine + #0;
  721. if not CreateProcess(nil, pchar(CommandLine),
  722. Nil, Nil, False,$20, Nil, Nil, SI, PI) then
  723. begin
  724. e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
  725. e.ErrorCode:=GetLastError;
  726. raise e;
  727. end;
  728. Proc:=PI.hProcess;
  729. if WaitForSingleObject(Proc, dword($ffffffff)) <> $ffffffff then
  730. begin
  731. GetExitCodeProcess(Proc,l);
  732. CloseHandle(Proc);
  733. CloseHandle(PI.hThread);
  734. result:=l;
  735. end
  736. else
  737. begin
  738. e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
  739. e.ErrorCode:=GetLastError;
  740. CloseHandle(Proc);
  741. CloseHandle(PI.hThread);
  742. raise e;
  743. end;
  744. end;
  745. function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString):integer;
  746. var
  747. CommandLine: AnsiString;
  748. I: integer;
  749. begin
  750. Commandline := '';
  751. for I := 0 to High (ComLine) do
  752. if Pos (' ', ComLine [I]) <> 0 then
  753. CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
  754. else
  755. CommandLine := CommandLine + ' ' + Comline [I];
  756. ExecuteProcess := ExecuteProcess (Path, CommandLine);
  757. end;
  758. Procedure Sleep(Milliseconds : Cardinal);
  759. begin
  760. Windows.Sleep(MilliSeconds)
  761. end;
  762. Function GetLastOSError : Integer;
  763. begin
  764. Result:=GetLastError;
  765. end;
  766. {****************************************************************************
  767. Initialization code
  768. ****************************************************************************}
  769. var
  770. kernel32dll : THandle;
  771. Procedure LoadVersionInfo;
  772. // and getfreespaceex
  773. Var
  774. versioninfo : TOSVERSIONINFO;
  775. begin
  776. kernel32dll:=0;
  777. GetDiskFreeSpaceEx:=nil;
  778. versioninfo.dwOSVersionInfoSize:=sizeof(versioninfo);
  779. GetVersionEx(versioninfo);
  780. Win32Platform:=versionInfo.dwPlatformId;
  781. Win32MajorVersion:=versionInfo.dwMajorVersion;
  782. Win32MinorVersion:=versionInfo.dwMinorVersion;
  783. Win32BuildNumber:=versionInfo.dwBuildNumber;
  784. Move (versioninfo.szCSDVersion ,Win32CSDVersion[1],128);
  785. win32CSDVersion[0]:=chr(strlen(pchar(@versioninfo.szCSDVersion)));
  786. if ((versioninfo.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS) and
  787. (versioninfo.dwBuildNUmber>=1000)) or
  788. (versioninfo.dwPlatformId=VER_PLATFORM_WIN32_NT) then
  789. begin
  790. kernel32dll:=LoadLibrary('kernel32');
  791. if kernel32dll<>0 then
  792. GetDiskFreeSpaceEx:=TGetDiskFreeSpaceEx(GetProcAddress(kernel32dll,'GetDiskFreeSpaceExA'));
  793. end;
  794. end;
  795. function FreeLibrary(hLibModule : THANDLE) : longbool;
  796. stdcall;external 'kernel32' name 'FreeLibrary';
  797. function GetVersionEx(var VersionInformation:TOSVERSIONINFO) : longbool;
  798. stdcall;external 'kernel32' name 'GetVersionExA';
  799. function LoadLibrary(lpLibFileName : pchar):THandle;
  800. stdcall;external 'kernel32' name 'LoadLibraryA';
  801. function GetProcAddress(hModule : THandle;lpProcName : pchar) : pointer;
  802. stdcall;external 'kernel32' name 'GetProcAddress';
  803. Const
  804. CSIDL_PROGRAMS = $0002; { %SYSTEMDRIVE%\Program Files }
  805. CSIDL_PERSONAL = $0005; { %USERPROFILE%\My Documents }
  806. CSIDL_FAVORITES = $0006; { %USERPROFILE%\Favorites }
  807. CSIDL_STARTUP = $0007; { %USERPROFILE%\Start menu\Programs\Startup }
  808. CSIDL_RECENT = $0008; { %USERPROFILE%\Recent }
  809. CSIDL_SENDTO = $0009; { %USERPROFILE%\Sendto }
  810. CSIDL_STARTMENU = $000B; { %USERPROFILE%\Start menu }
  811. CSIDL_MYMUSIC = $000D; { %USERPROFILE%\Documents\My Music }
  812. CSIDL_MYVIDEO = $000E; { %USERPROFILE%\Documents\My Videos }
  813. CSIDL_DESKTOPDIRECTORY = $0010; { %USERPROFILE%\Desktop }
  814. CSIDL_NETHOOD = $0013; { %USERPROFILE%\NetHood }
  815. CSIDL_TEMPLATES = $0015; { %USERPROFILE%\Templates }
  816. CSIDL_COMMON_STARTMENU = $0016; { %PROFILEPATH%\All users\Start menu }
  817. CSIDL_COMMON_PROGRAMS = $0017; { %PROFILEPATH%\All users\Start menu\Programs }
  818. CSIDL_COMMON_STARTUP = $0018; { %PROFILEPATH%\All users\Start menu\Programs\Startup }
  819. CSIDL_COMMON_DESKTOPDIRECTORY = $0019; { %PROFILEPATH%\All users\Desktop }
  820. CSIDL_APPDATA = $001A; { %USERPROFILE%\Application Data (roaming) }
  821. CSIDL_PRINTHOOD = $001B; { %USERPROFILE%\Printhood }
  822. CSIDL_LOCAL_APPDATA = $001C; { %USERPROFILE%\Local Settings\Application Data (non roaming) }
  823. CSIDL_COMMON_FAVORITES = $001F; { %PROFILEPATH%\All users\Favorites }
  824. CSIDL_INTERNET_CACHE = $0020; { %USERPROFILE%\Local Settings\Temporary Internet Files }
  825. CSIDL_COOKIES = $0021; { %USERPROFILE%\Cookies }
  826. CSIDL_HISTORY = $0022; { %USERPROFILE%\Local settings\History }
  827. CSIDL_COMMON_APPDATA = $0023; { %PROFILESPATH%\All Users\Application Data }
  828. CSIDL_WINDOWS = $0024; { %SYSTEMROOT% }
  829. CSIDL_SYSTEM = $0025; { %SYSTEMROOT%\SYSTEM32 (may be system on 95/98/ME) }
  830. CSIDL_PROGRAM_FILES = $0026; { %SYSTEMDRIVE%\Program Files }
  831. CSIDL_MYPICTURES = $0027; { %USERPROFILE%\My Documents\My Pictures }
  832. CSIDL_PROFILE = $0028; { %USERPROFILE% }
  833. CSIDL_PROGRAM_FILES_COMMON = $002B; { %SYSTEMDRIVE%\Program Files\Common }
  834. CSIDL_COMMON_TEMPLATES = $002D; { %PROFILEPATH%\All Users\Templates }
  835. CSIDL_COMMON_DOCUMENTS = $002E; { %PROFILEPATH%\All Users\Documents }
  836. CSIDL_COMMON_ADMINTOOLS = $002F; { %PROFILEPATH%\All Users\Start Menu\Programs\Administrative Tools }
  837. CSIDL_ADMINTOOLS = $0030; { %USERPROFILE%\Start Menu\Programs\Administrative Tools }
  838. CSIDL_COMMON_MUSIC = $0035; { %PROFILEPATH%\All Users\Documents\my music }
  839. CSIDL_COMMON_PICTURES = $0036; { %PROFILEPATH%\All Users\Documents\my pictures }
  840. CSIDL_COMMON_VIDEO = $0037; { %PROFILEPATH%\All Users\Documents\my videos }
  841. CSIDL_CDBURN_AREA = $003B; { %USERPROFILE%\Local Settings\Application Data\Microsoft\CD Burning }
  842. CSIDL_PROFILES = $003E; { %PROFILEPATH% }
  843. CSIDL_FLAG_CREATE = $8000; { (force creation of requested folder if it doesn't exist yet) }
  844. Type
  845. PFNSHGetFolderPath = Function(Ahwnd: HWND; Csidl: Integer; Token: THandle; Flags: DWord; Path: PChar): HRESULT; stdcall;
  846. var
  847. SHGetFolderPath : PFNSHGetFolderPath = Nil;
  848. CFGDLLHandle : THandle = 0;
  849. Procedure InitDLL;
  850. Var
  851. P : Pointer;
  852. begin
  853. CFGDLLHandle:=LoadLibrary('shell32.dll');
  854. if (CFGDLLHandle<>0) then
  855. begin
  856. P:=GetProcAddress(CFGDLLHandle,'SHGetFolderPathA');
  857. If (P=Nil) then
  858. begin
  859. FreeLibrary(CFGDLLHandle);
  860. CFGDllHandle:=0;
  861. end
  862. else
  863. SHGetFolderPath:=PFNSHGetFolderPath(P);
  864. end;
  865. If (P=Nil) then
  866. begin
  867. CFGDLLHandle:=LoadLibrary('shfolder.dll');
  868. if (CFGDLLHandle<>0) then
  869. begin
  870. P:=GetProcAddress(CFGDLLHandle,'SHGetFolderPathA');
  871. If (P=Nil) then
  872. begin
  873. FreeLibrary(CFGDLLHandle);
  874. CFGDllHandle:=0;
  875. end
  876. else
  877. ShGetFolderPath:=PFNSHGetFolderPath(P);
  878. end;
  879. end;
  880. If (@ShGetFolderPath=Nil) then
  881. Raise Exception.Create('Could not determine SHGetFolderPath Function');
  882. end;
  883. Function GetSpecialDir(ID : Integer) : String;
  884. Var
  885. APath : Array[0..MAX_PATH] of char;
  886. begin
  887. Result:='';
  888. if (CFGDLLHandle=0) then
  889. InitDLL;
  890. If (SHGetFolderPath<>Nil) then
  891. begin
  892. if SHGetFolderPath(0,ID or CSIDL_FLAG_CREATE,0,0,@APATH[0])=S_OK then
  893. Result:=IncludeTrailingPathDelimiter(StrPas(@APath[0]));
  894. end;
  895. end;
  896. Function GetAppConfigDir(Global : Boolean) : String;
  897. begin
  898. If Global then
  899. Result:=GetSpecialDir(CSIDL_COMMON_APPDATA)
  900. else
  901. Result:=GetSpecialDir(CSIDL_LOCAL_APPDATA);
  902. If (Result<>'') then
  903. begin
  904. if VendorName<>'' then
  905. Result:=IncludeTrailingPathDelimiter(Result+VendorName);
  906. Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
  907. end
  908. else
  909. Result:=IncludeTrailingPathDelimiter(DGetAppConfigDir(Global));
  910. end;
  911. Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
  912. begin
  913. result:=DGetAppConfigFile(Global,SubDir);
  914. end;
  915. Function GetUserDir : String;
  916. begin
  917. Result:=GetSpecialDir(CSIDL_PROFILE);
  918. end;
  919. Procedure InitSysConfigDir;
  920. begin
  921. SetLength(SysConfigDir, MAX_PATH);
  922. SetLength(SysConfigDir, GetWindowsDirectory(PChar(SysConfigDir), MAX_PATH));
  923. end;
  924. {****************************************************************************
  925. Target Dependent WideString stuff
  926. ****************************************************************************}
  927. { This is the case of Win9x. Limited to current locale of course, but it's better
  928. than not working at all. }
  929. function DoCompareStringA(const s1, s2: WideString; Flags: DWORD): PtrInt;
  930. var
  931. a1, a2: AnsiString;
  932. begin
  933. a1:=s1;
  934. a2:=s2;
  935. SetLastError(0);
  936. Result:=CompareStringA(LOCALE_USER_DEFAULT,Flags,pchar(a1),
  937. length(a1),pchar(a2),length(a2))-2;
  938. end;
  939. function DoCompareStringW(const s1, s2: WideString; Flags: DWORD): PtrInt;
  940. begin
  941. SetLastError(0);
  942. Result:=CompareStringW(LOCALE_USER_DEFAULT,Flags,pwidechar(s1),
  943. length(s1),pwidechar(s2),length(s2))-2;
  944. if GetLastError=0 then
  945. Exit;
  946. if GetLastError=ERROR_CALL_NOT_IMPLEMENTED then // Win9x case
  947. Result:=DoCompareStringA(s1, s2, Flags);
  948. if GetLastError<>0 then
  949. RaiseLastOSError;
  950. end;
  951. function Win32CompareWideString(const s1, s2 : WideString) : PtrInt;
  952. begin
  953. Result:=DoCompareStringW(s1, s2, 0);
  954. end;
  955. function Win32CompareTextWideString(const s1, s2 : WideString) : PtrInt;
  956. begin
  957. Result:=DoCompareStringW(s1, s2, NORM_IGNORECASE);
  958. end;
  959. function Win32AnsiUpperCase(const s: string): string;
  960. begin
  961. if length(s)>0 then
  962. begin
  963. result:=s;
  964. UniqueString(result);
  965. CharUpperBuff(pchar(result),length(result));
  966. end
  967. else
  968. result:='';
  969. end;
  970. function Win32AnsiLowerCase(const s: string): string;
  971. begin
  972. if length(s)>0 then
  973. begin
  974. result:=s;
  975. UniqueString(result);
  976. CharLowerBuff(pchar(result),length(result));
  977. end
  978. else
  979. result:='';
  980. end;
  981. function Win32AnsiCompareStr(const S1, S2: string): PtrInt;
  982. begin
  983. result:=CompareString(LOCALE_USER_DEFAULT,0,pchar(s1),length(s1),
  984. pchar(s2),length(s2))-2;
  985. end;
  986. function Win32AnsiCompareText(const S1, S2: string): PtrInt;
  987. begin
  988. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,pchar(s1),length(s1),
  989. pchar(s2),length(s2))-2;
  990. end;
  991. function Win32AnsiStrComp(S1, S2: PChar): PtrInt;
  992. begin
  993. result:=CompareString(LOCALE_USER_DEFAULT,0,s1,-1,s2,-1)-2;
  994. end;
  995. function Win32AnsiStrIComp(S1, S2: PChar): PtrInt;
  996. begin
  997. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,-1,s2,-1)-2;
  998. end;
  999. function Win32AnsiStrLComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  1000. begin
  1001. result:=CompareString(LOCALE_USER_DEFAULT,0,s1,maxlen,s2,maxlen)-2;
  1002. end;
  1003. function Win32AnsiStrLIComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  1004. begin
  1005. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,maxlen,s2,maxlen)-2;
  1006. end;
  1007. function Win32AnsiStrLower(Str: PChar): PChar;
  1008. begin
  1009. CharLower(str);
  1010. result:=str;
  1011. end;
  1012. function Win32AnsiStrUpper(Str: PChar): PChar;
  1013. begin
  1014. CharUpper(str);
  1015. result:=str;
  1016. end;
  1017. { there is a similiar procedure in the system unit which inits the fields which
  1018. are relevant already for the system unit }
  1019. procedure InitWin32Widestrings;
  1020. begin
  1021. //!!! CharLengthPCharProc : function(const Str: PChar): PtrInt;
  1022. widestringmanager.CompareWideStringProc:=@Win32CompareWideString;
  1023. widestringmanager.CompareTextWideStringProc:=@Win32CompareTextWideString;
  1024. widestringmanager.UpperAnsiStringProc:=@Win32AnsiUpperCase;
  1025. widestringmanager.LowerAnsiStringProc:=@Win32AnsiLowerCase;
  1026. widestringmanager.CompareStrAnsiStringProc:=@Win32AnsiCompareStr;
  1027. widestringmanager.CompareTextAnsiStringProc:=@Win32AnsiCompareText;
  1028. widestringmanager.StrCompAnsiStringProc:=@Win32AnsiStrComp;
  1029. widestringmanager.StrICompAnsiStringProc:=@Win32AnsiStrIComp;
  1030. widestringmanager.StrLCompAnsiStringProc:=@Win32AnsiStrLComp;
  1031. widestringmanager.StrLICompAnsiStringProc:=@Win32AnsiStrLIComp;
  1032. widestringmanager.StrLowerAnsiStringProc:=@Win32AnsiStrLower;
  1033. widestringmanager.StrUpperAnsiStringProc:=@Win32AnsiStrUpper;
  1034. end;
  1035. Initialization
  1036. InitWin32Widestrings;
  1037. InitExceptions; { Initialize exceptions. OS independent }
  1038. InitInternational; { Initialize internationalization settings }
  1039. LoadVersionInfo;
  1040. InitSysConfigDir;
  1041. Finalization
  1042. DoneExceptions;
  1043. if kernel32dll<>0 then
  1044. FreeLibrary(kernel32dll);
  1045. if CFGDLLHandle<>0 then
  1046. FreeLibrary(CFGDllHandle);
  1047. end.