sysutils.pp 36 KB

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