sysutils.pp 36 KB

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