sysutils.pp 35 KB

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