sysutils.pp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  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 sysbeep;
  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;Flags:TExecuteFlags=[]):integer;
  697. // win specific function
  698. var
  699. SI: TStartupInfo;
  700. PI: TProcessInformation;
  701. Proc : THandle;
  702. l : DWord;
  703. CommandLine : ansistring;
  704. e : EOSError;
  705. ExecInherits : longbool;
  706. begin
  707. FillChar(SI, SizeOf(SI), 0);
  708. SI.cb:=SizeOf(SI);
  709. SI.wShowWindow:=1;
  710. { always surround the name of the application by quotes
  711. so that long filenames will always be accepted. But don't
  712. do it if there are already double quotes, since Win32 does not
  713. like double quotes which are duplicated!
  714. }
  715. if pos('"',path)=0 then
  716. CommandLine:='"'+path+'"'
  717. else
  718. CommandLine:=path;
  719. if ComLine <> '' then
  720. CommandLine:=Commandline+' '+ComLine+#0
  721. else
  722. CommandLine := CommandLine + #0;
  723. ExecInherits:=ExecInheritsHandles in Flags;
  724. if not CreateProcess(nil, pchar(CommandLine),
  725. Nil, Nil, ExecInherits,$20, Nil, Nil, SI, PI) then
  726. begin
  727. e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
  728. e.ErrorCode:=GetLastError;
  729. raise e;
  730. end;
  731. Proc:=PI.hProcess;
  732. if WaitForSingleObject(Proc, dword($ffffffff)) <> $ffffffff then
  733. begin
  734. GetExitCodeProcess(Proc,l);
  735. CloseHandle(Proc);
  736. CloseHandle(PI.hThread);
  737. result:=l;
  738. end
  739. else
  740. begin
  741. e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
  742. e.ErrorCode:=GetLastError;
  743. CloseHandle(Proc);
  744. CloseHandle(PI.hThread);
  745. raise e;
  746. end;
  747. end;
  748. function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString;Flags:TExecuteFlags=[]):integer;
  749. var
  750. CommandLine: AnsiString;
  751. I: integer;
  752. begin
  753. Commandline := '';
  754. for I := 0 to High (ComLine) do
  755. if Pos (' ', ComLine [I]) <> 0 then
  756. CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
  757. else
  758. CommandLine := CommandLine + ' ' + Comline [I];
  759. ExecuteProcess := ExecuteProcess (Path, CommandLine,Flags);
  760. end;
  761. Procedure Sleep(Milliseconds : Cardinal);
  762. begin
  763. Windows.Sleep(MilliSeconds)
  764. end;
  765. Function GetLastOSError : Integer;
  766. begin
  767. Result:=GetLastError;
  768. end;
  769. {****************************************************************************
  770. Initialization code
  771. ****************************************************************************}
  772. var
  773. kernel32dll : THandle;
  774. Procedure LoadVersionInfo;
  775. // and getfreespaceex
  776. Var
  777. versioninfo : TOSVERSIONINFO;
  778. begin
  779. kernel32dll:=0;
  780. GetDiskFreeSpaceEx:=nil;
  781. versioninfo.dwOSVersionInfoSize:=sizeof(versioninfo);
  782. GetVersionEx(versioninfo);
  783. Win32Platform:=versionInfo.dwPlatformId;
  784. Win32MajorVersion:=versionInfo.dwMajorVersion;
  785. Win32MinorVersion:=versionInfo.dwMinorVersion;
  786. Win32BuildNumber:=versionInfo.dwBuildNumber;
  787. Move (versioninfo.szCSDVersion ,Win32CSDVersion[1],128);
  788. win32CSDVersion[0]:=chr(strlen(pchar(@versioninfo.szCSDVersion)));
  789. if ((versioninfo.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS) and
  790. (versioninfo.dwBuildNUmber>=1000)) or
  791. (versioninfo.dwPlatformId=VER_PLATFORM_WIN32_NT) then
  792. begin
  793. kernel32dll:=LoadLibrary('kernel32');
  794. if kernel32dll<>0 then
  795. GetDiskFreeSpaceEx:=TGetDiskFreeSpaceEx(GetProcAddress(kernel32dll,'GetDiskFreeSpaceExA'));
  796. end;
  797. end;
  798. function FreeLibrary(hLibModule : THANDLE) : longbool;
  799. stdcall;external 'kernel32' name 'FreeLibrary';
  800. function GetVersionEx(var VersionInformation:TOSVERSIONINFO) : longbool;
  801. stdcall;external 'kernel32' name 'GetVersionExA';
  802. function LoadLibrary(lpLibFileName : pchar):THandle;
  803. stdcall;external 'kernel32' name 'LoadLibraryA';
  804. function GetProcAddress(hModule : THandle;lpProcName : pchar) : pointer;
  805. stdcall;external 'kernel32' name 'GetProcAddress';
  806. Const
  807. CSIDL_PROGRAMS = $0002; { %SYSTEMDRIVE%\Program Files }
  808. CSIDL_PERSONAL = $0005; { %USERPROFILE%\My Documents }
  809. CSIDL_FAVORITES = $0006; { %USERPROFILE%\Favorites }
  810. CSIDL_STARTUP = $0007; { %USERPROFILE%\Start menu\Programs\Startup }
  811. CSIDL_RECENT = $0008; { %USERPROFILE%\Recent }
  812. CSIDL_SENDTO = $0009; { %USERPROFILE%\Sendto }
  813. CSIDL_STARTMENU = $000B; { %USERPROFILE%\Start menu }
  814. CSIDL_MYMUSIC = $000D; { %USERPROFILE%\Documents\My Music }
  815. CSIDL_MYVIDEO = $000E; { %USERPROFILE%\Documents\My Videos }
  816. CSIDL_DESKTOPDIRECTORY = $0010; { %USERPROFILE%\Desktop }
  817. CSIDL_NETHOOD = $0013; { %USERPROFILE%\NetHood }
  818. CSIDL_TEMPLATES = $0015; { %USERPROFILE%\Templates }
  819. CSIDL_COMMON_STARTMENU = $0016; { %PROFILEPATH%\All users\Start menu }
  820. CSIDL_COMMON_PROGRAMS = $0017; { %PROFILEPATH%\All users\Start menu\Programs }
  821. CSIDL_COMMON_STARTUP = $0018; { %PROFILEPATH%\All users\Start menu\Programs\Startup }
  822. CSIDL_COMMON_DESKTOPDIRECTORY = $0019; { %PROFILEPATH%\All users\Desktop }
  823. CSIDL_APPDATA = $001A; { %USERPROFILE%\Application Data (roaming) }
  824. CSIDL_PRINTHOOD = $001B; { %USERPROFILE%\Printhood }
  825. CSIDL_LOCAL_APPDATA = $001C; { %USERPROFILE%\Local Settings\Application Data (non roaming) }
  826. CSIDL_COMMON_FAVORITES = $001F; { %PROFILEPATH%\All users\Favorites }
  827. CSIDL_INTERNET_CACHE = $0020; { %USERPROFILE%\Local Settings\Temporary Internet Files }
  828. CSIDL_COOKIES = $0021; { %USERPROFILE%\Cookies }
  829. CSIDL_HISTORY = $0022; { %USERPROFILE%\Local settings\History }
  830. CSIDL_COMMON_APPDATA = $0023; { %PROFILESPATH%\All Users\Application Data }
  831. CSIDL_WINDOWS = $0024; { %SYSTEMROOT% }
  832. CSIDL_SYSTEM = $0025; { %SYSTEMROOT%\SYSTEM32 (may be system on 95/98/ME) }
  833. CSIDL_PROGRAM_FILES = $0026; { %SYSTEMDRIVE%\Program Files }
  834. CSIDL_MYPICTURES = $0027; { %USERPROFILE%\My Documents\My Pictures }
  835. CSIDL_PROFILE = $0028; { %USERPROFILE% }
  836. CSIDL_PROGRAM_FILES_COMMON = $002B; { %SYSTEMDRIVE%\Program Files\Common }
  837. CSIDL_COMMON_TEMPLATES = $002D; { %PROFILEPATH%\All Users\Templates }
  838. CSIDL_COMMON_DOCUMENTS = $002E; { %PROFILEPATH%\All Users\Documents }
  839. CSIDL_COMMON_ADMINTOOLS = $002F; { %PROFILEPATH%\All Users\Start Menu\Programs\Administrative Tools }
  840. CSIDL_ADMINTOOLS = $0030; { %USERPROFILE%\Start Menu\Programs\Administrative Tools }
  841. CSIDL_COMMON_MUSIC = $0035; { %PROFILEPATH%\All Users\Documents\my music }
  842. CSIDL_COMMON_PICTURES = $0036; { %PROFILEPATH%\All Users\Documents\my pictures }
  843. CSIDL_COMMON_VIDEO = $0037; { %PROFILEPATH%\All Users\Documents\my videos }
  844. CSIDL_CDBURN_AREA = $003B; { %USERPROFILE%\Local Settings\Application Data\Microsoft\CD Burning }
  845. CSIDL_PROFILES = $003E; { %PROFILEPATH% }
  846. CSIDL_FLAG_CREATE = $8000; { (force creation of requested folder if it doesn't exist yet) }
  847. Type
  848. PFNSHGetFolderPath = Function(Ahwnd: HWND; Csidl: Integer; Token: THandle; Flags: DWord; Path: PChar): HRESULT; stdcall;
  849. var
  850. SHGetFolderPath : PFNSHGetFolderPath = Nil;
  851. CFGDLLHandle : THandle = 0;
  852. Procedure InitDLL;
  853. Var
  854. P : Pointer;
  855. begin
  856. CFGDLLHandle:=LoadLibrary('shell32.dll');
  857. if (CFGDLLHandle<>0) then
  858. begin
  859. P:=GetProcAddress(CFGDLLHandle,'SHGetFolderPathA');
  860. If (P=Nil) then
  861. begin
  862. FreeLibrary(CFGDLLHandle);
  863. CFGDllHandle:=0;
  864. end
  865. else
  866. SHGetFolderPath:=PFNSHGetFolderPath(P);
  867. end;
  868. If (P=Nil) then
  869. begin
  870. CFGDLLHandle:=LoadLibrary('shfolder.dll');
  871. if (CFGDLLHandle<>0) then
  872. begin
  873. P:=GetProcAddress(CFGDLLHandle,'SHGetFolderPathA');
  874. If (P=Nil) then
  875. begin
  876. FreeLibrary(CFGDLLHandle);
  877. CFGDllHandle:=0;
  878. end
  879. else
  880. ShGetFolderPath:=PFNSHGetFolderPath(P);
  881. end;
  882. end;
  883. If (@ShGetFolderPath=Nil) then
  884. Raise Exception.Create('Could not determine SHGetFolderPath Function');
  885. end;
  886. Function GetSpecialDir(ID : Integer) : String;
  887. Var
  888. APath : Array[0..MAX_PATH] of char;
  889. begin
  890. Result:='';
  891. if (CFGDLLHandle=0) then
  892. InitDLL;
  893. If (SHGetFolderPath<>Nil) then
  894. begin
  895. if SHGetFolderPath(0,ID or CSIDL_FLAG_CREATE,0,0,@APATH[0])=S_OK then
  896. Result:=IncludeTrailingPathDelimiter(StrPas(@APath[0]));
  897. end;
  898. end;
  899. Function GetAppConfigDir(Global : Boolean) : String;
  900. begin
  901. If Global then
  902. Result:=GetSpecialDir(CSIDL_COMMON_APPDATA)
  903. else
  904. Result:=GetSpecialDir(CSIDL_LOCAL_APPDATA);
  905. If (Result<>'') then
  906. begin
  907. if VendorName<>'' then
  908. Result:=IncludeTrailingPathDelimiter(Result+VendorName);
  909. Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
  910. end
  911. else
  912. Result:=IncludeTrailingPathDelimiter(DGetAppConfigDir(Global));
  913. end;
  914. Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
  915. begin
  916. result:=DGetAppConfigFile(Global,SubDir);
  917. end;
  918. Function GetUserDir : String;
  919. begin
  920. Result:=GetSpecialDir(CSIDL_PROFILE);
  921. end;
  922. Procedure InitSysConfigDir;
  923. begin
  924. SetLength(SysConfigDir, MAX_PATH);
  925. SetLength(SysConfigDir, GetWindowsDirectory(PChar(SysConfigDir), MAX_PATH));
  926. end;
  927. {****************************************************************************
  928. Target Dependent WideString stuff
  929. ****************************************************************************}
  930. { This is the case of Win9x. Limited to current locale of course, but it's better
  931. than not working at all. }
  932. function DoCompareStringA(const s1, s2: WideString; Flags: DWORD): PtrInt;
  933. var
  934. a1, a2: AnsiString;
  935. begin
  936. a1:=s1;
  937. a2:=s2;
  938. SetLastError(0);
  939. Result:=CompareStringA(LOCALE_USER_DEFAULT,Flags,pchar(a1),
  940. length(a1),pchar(a2),length(a2))-2;
  941. end;
  942. function DoCompareStringW(const s1, s2: WideString; Flags: DWORD): PtrInt;
  943. begin
  944. SetLastError(0);
  945. Result:=CompareStringW(LOCALE_USER_DEFAULT,Flags,pwidechar(s1),
  946. length(s1),pwidechar(s2),length(s2))-2;
  947. if GetLastError=0 then
  948. Exit;
  949. if GetLastError=ERROR_CALL_NOT_IMPLEMENTED then // Win9x case
  950. Result:=DoCompareStringA(s1, s2, Flags);
  951. if GetLastError<>0 then
  952. RaiseLastOSError;
  953. end;
  954. function Win32CompareWideString(const s1, s2 : WideString) : PtrInt;
  955. begin
  956. Result:=DoCompareStringW(s1, s2, 0);
  957. end;
  958. function Win32CompareTextWideString(const s1, s2 : WideString) : PtrInt;
  959. begin
  960. Result:=DoCompareStringW(s1, s2, NORM_IGNORECASE);
  961. end;
  962. function Win32AnsiUpperCase(const s: string): string;
  963. begin
  964. if length(s)>0 then
  965. begin
  966. result:=s;
  967. UniqueString(result);
  968. CharUpperBuff(pchar(result),length(result));
  969. end
  970. else
  971. result:='';
  972. end;
  973. function Win32AnsiLowerCase(const s: string): string;
  974. begin
  975. if length(s)>0 then
  976. begin
  977. result:=s;
  978. UniqueString(result);
  979. CharLowerBuff(pchar(result),length(result));
  980. end
  981. else
  982. result:='';
  983. end;
  984. function Win32AnsiCompareStr(const S1, S2: string): PtrInt;
  985. begin
  986. result:=CompareString(LOCALE_USER_DEFAULT,0,pchar(s1),length(s1),
  987. pchar(s2),length(s2))-2;
  988. end;
  989. function Win32AnsiCompareText(const S1, S2: string): PtrInt;
  990. begin
  991. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,pchar(s1),length(s1),
  992. pchar(s2),length(s2))-2;
  993. end;
  994. function Win32AnsiStrComp(S1, S2: PChar): PtrInt;
  995. begin
  996. result:=CompareString(LOCALE_USER_DEFAULT,0,s1,-1,s2,-1)-2;
  997. end;
  998. function Win32AnsiStrIComp(S1, S2: PChar): PtrInt;
  999. begin
  1000. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,-1,s2,-1)-2;
  1001. end;
  1002. function Win32AnsiStrLComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  1003. begin
  1004. result:=CompareString(LOCALE_USER_DEFAULT,0,s1,maxlen,s2,maxlen)-2;
  1005. end;
  1006. function Win32AnsiStrLIComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  1007. begin
  1008. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,maxlen,s2,maxlen)-2;
  1009. end;
  1010. function Win32AnsiStrLower(Str: PChar): PChar;
  1011. begin
  1012. CharLower(str);
  1013. result:=str;
  1014. end;
  1015. function Win32AnsiStrUpper(Str: PChar): PChar;
  1016. begin
  1017. CharUpper(str);
  1018. result:=str;
  1019. end;
  1020. { there is a similiar procedure in the system unit which inits the fields which
  1021. are relevant already for the system unit }
  1022. procedure InitWin32Widestrings;
  1023. begin
  1024. //!!! CharLengthPCharProc : function(const Str: PChar): PtrInt;
  1025. widestringmanager.CompareWideStringProc:=@Win32CompareWideString;
  1026. widestringmanager.CompareTextWideStringProc:=@Win32CompareTextWideString;
  1027. widestringmanager.UpperAnsiStringProc:=@Win32AnsiUpperCase;
  1028. widestringmanager.LowerAnsiStringProc:=@Win32AnsiLowerCase;
  1029. widestringmanager.CompareStrAnsiStringProc:=@Win32AnsiCompareStr;
  1030. widestringmanager.CompareTextAnsiStringProc:=@Win32AnsiCompareText;
  1031. widestringmanager.StrCompAnsiStringProc:=@Win32AnsiStrComp;
  1032. widestringmanager.StrICompAnsiStringProc:=@Win32AnsiStrIComp;
  1033. widestringmanager.StrLCompAnsiStringProc:=@Win32AnsiStrLComp;
  1034. widestringmanager.StrLICompAnsiStringProc:=@Win32AnsiStrLIComp;
  1035. widestringmanager.StrLowerAnsiStringProc:=@Win32AnsiStrLower;
  1036. widestringmanager.StrUpperAnsiStringProc:=@Win32AnsiStrUpper;
  1037. end;
  1038. Initialization
  1039. InitWin32Widestrings;
  1040. InitExceptions; { Initialize exceptions. OS independent }
  1041. InitInternational; { Initialize internationalization settings }
  1042. LoadVersionInfo;
  1043. InitSysConfigDir;
  1044. OnBeep:=@SysBeep;
  1045. Finalization
  1046. DoneExceptions;
  1047. if kernel32dll<>0 then
  1048. FreeLibrary(kernel32dll);
  1049. if CFGDLLHandle<>0 then
  1050. FreeLibrary(CFGDllHandle);
  1051. end.