sysutils.pp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  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. {$DEFINE HAS_LOCALTIMEZONEOFFSET}
  26. { Include platform independent interface part }
  27. {$i sysutilh.inc}
  28. type
  29. TSystemTime = Windows.TSystemTime;
  30. EWin32Error = class(Exception)
  31. public
  32. ErrorCode : DWORD;
  33. end;
  34. Var
  35. Win32Platform : Longint;
  36. Win32MajorVersion,
  37. Win32MinorVersion,
  38. Win32BuildNumber : dword;
  39. Win32CSDVersion : ShortString; // CSD record is 128 bytes only?
  40. const
  41. MaxEraCount = 7;
  42. var
  43. EraNames: array [1..MaxEraCount] of String;
  44. EraYearOffsets: array [1..MaxEraCount] of Integer;
  45. { Compatibility with Delphi }
  46. function Win32Check(res:boolean):boolean;inline;
  47. function WinCheck(res:boolean):boolean;
  48. function CheckWin32Version(Major,Minor : Integer ): Boolean;
  49. function CheckWin32Version(Major : Integer): Boolean;
  50. Procedure RaiseLastWin32Error;
  51. function GetFileVersion(const AFileName: string): Cardinal;
  52. procedure GetFormatSettings;
  53. procedure GetLocaleFormatSettings(LCID: Integer; var FormatSettings: TFormatSettings); platform;
  54. implementation
  55. uses
  56. sysconst,
  57. windirs;
  58. function WinCheck(res:boolean):boolean;
  59. begin
  60. if not res then
  61. RaiseLastOSError;
  62. result:=res;
  63. end;
  64. function Win32Check(res:boolean):boolean;inline;
  65. begin
  66. result:=WinCheck(res);
  67. end;
  68. procedure RaiseLastWin32Error;
  69. begin
  70. RaiseLastOSError;
  71. end;
  72. function CheckWin32Version(Major : Integer): Boolean;
  73. begin
  74. Result:=CheckWin32Version(Major,0)
  75. end;
  76. function CheckWin32Version(Major,Minor: Integer): Boolean;
  77. begin
  78. Result:=(Win32MajorVersion>dword(Major)) or
  79. ((Win32MajorVersion=dword(Major)) and (Win32MinorVersion>=dword(Minor)));
  80. end;
  81. function GetFileVersion(const AFileName:string):Cardinal;
  82. var
  83. { useful only as long as we don't need to touch different stack pages }
  84. buf : array[0..3071] of byte;
  85. bufp : pointer;
  86. fn : string;
  87. valsize,
  88. size : DWORD;
  89. h : DWORD;
  90. valrec : PVSFixedFileInfo;
  91. begin
  92. result:=$fffffff;
  93. fn:=AFileName;
  94. UniqueString(fn);
  95. size:=GetFileVersionInfoSize(pchar(fn),@h);
  96. if size>sizeof(buf) then
  97. begin
  98. getmem(bufp,size);
  99. try
  100. if GetFileVersionInfo(pchar(fn),h,size,bufp) then
  101. if VerQueryValue(bufp,'\',valrec,valsize) then
  102. result:=valrec^.dwFileVersionMS;
  103. finally
  104. freemem(bufp);
  105. end;
  106. end
  107. else
  108. begin
  109. if GetFileVersionInfo(pchar(fn),h,size,@buf) then
  110. if VerQueryValue(@buf,'\',valrec,valsize) then
  111. result:=valrec^.dwFileVersionMS;
  112. end;
  113. end;
  114. {$define HASCREATEGUID}
  115. {$define HASEXPANDUNCFILENAME}
  116. {$DEFINE FPC_NOGENERICANSIROUTINES}
  117. {$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
  118. {$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
  119. function ConvertEraYearString(Count ,Year,Month,Day : integer) : string; forward;
  120. function ConvertEraString(Count ,Year,Month,Day : integer) : string; forward;
  121. { Include platform independent implementation part }
  122. {$i sysutils.inc}
  123. function GetTempFileName(Dir,Prefix: PChar; uUnique: DWORD; TempFileName: PChar):DWORD;
  124. begin
  125. Result:= Windows.GetTempFileNameA(Dir,Prefix,uUnique,TempFileName);
  126. end;
  127. { UUID generation. }
  128. function CoCreateGuid(out guid: TGUID): HResult; stdcall; external 'ole32.dll' name 'CoCreateGuid';
  129. function SysCreateGUID(out Guid: TGUID): Integer;
  130. begin
  131. Result := Integer(CoCreateGuid(Guid));
  132. end;
  133. function ExpandUNCFileName (const filename:string) : string;
  134. { returns empty string on errors }
  135. var
  136. s : ansistring;
  137. size : dword;
  138. rc : dword;
  139. buf : pchar;
  140. begin
  141. s := ExpandFileName (filename);
  142. s := s + #0;
  143. size := max_path;
  144. getmem(buf,size);
  145. try
  146. rc := WNetGetUniversalName (pchar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
  147. if rc=ERROR_MORE_DATA then
  148. begin
  149. buf:=reallocmem(buf,size);
  150. rc := WNetGetUniversalName (pchar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
  151. end;
  152. if rc = NO_ERROR then
  153. Result := PRemoteNameInfo(buf)^.lpUniversalName
  154. else if rc = ERROR_NOT_CONNECTED then
  155. Result := filename
  156. else
  157. Result := '';
  158. finally
  159. freemem(buf);
  160. end;
  161. end;
  162. {****************************************************************************
  163. File Functions
  164. ****************************************************************************}
  165. const
  166. AccessMode: array[0..2] of Cardinal = (
  167. GENERIC_READ,
  168. GENERIC_WRITE,
  169. GENERIC_READ or GENERIC_WRITE);
  170. ShareModes: 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. Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
  177. begin
  178. result := CreateFile(PChar(FileName), dword(AccessMode[Mode and 3]),
  179. dword(ShareModes[(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. begin
  185. FileCreate:=FileCreate(FileName, fmShareExclusive, 0);
  186. end;
  187. Function FileCreate (Const FileName : String; Rights:longint) : THandle;
  188. begin
  189. FileCreate:=FileCreate(FileName, fmShareExclusive, Rights);
  190. end;
  191. Function FileCreate (Const FileName : String; ShareMode : Integer; Rights : Integer) : THandle;
  192. begin
  193. Result := CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE,
  194. dword(ShareModes[(ShareMode and $F0) shr 4]), nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  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:=Longint(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. type
  381. TGetDiskFreeSpaceEx = function(drive:pchar;var availableforcaller,total,free):longbool;stdcall;
  382. var
  383. GetDiskFreeSpaceEx : TGetDiskFreeSpaceEx;
  384. function diskfree(drive : byte) : int64;
  385. var
  386. disk : array[1..4] of char;
  387. secs,bytes,
  388. free,total : dword;
  389. qwtotal,qwfree,qwcaller : int64;
  390. begin
  391. if drive=0 then
  392. begin
  393. disk[1]:='\';
  394. disk[2]:=#0;
  395. end
  396. else
  397. begin
  398. disk[1]:=chr(drive+64);
  399. disk[2]:=':';
  400. disk[3]:='\';
  401. disk[4]:=#0;
  402. end;
  403. if assigned(GetDiskFreeSpaceEx) then
  404. begin
  405. if GetDiskFreeSpaceEx(@disk[1],qwcaller,qwtotal,qwfree) then
  406. diskfree:=qwfree
  407. else
  408. diskfree:=-1;
  409. end
  410. else
  411. begin
  412. if GetDiskFreeSpace(@disk[1],secs,bytes,free,total) then
  413. diskfree:=int64(free)*secs*bytes
  414. else
  415. diskfree:=-1;
  416. end;
  417. end;
  418. function disksize(drive : byte) : int64;
  419. var
  420. disk : array[1..4] of char;
  421. secs,bytes,
  422. free,total : dword;
  423. qwtotal,qwfree,qwcaller : int64;
  424. begin
  425. if drive=0 then
  426. begin
  427. disk[1]:='\';
  428. disk[2]:=#0;
  429. end
  430. else
  431. begin
  432. disk[1]:=chr(drive+64);
  433. disk[2]:=':';
  434. disk[3]:='\';
  435. disk[4]:=#0;
  436. end;
  437. if assigned(GetDiskFreeSpaceEx) then
  438. begin
  439. if GetDiskFreeSpaceEx(@disk[1],qwcaller,qwtotal,qwfree) then
  440. disksize:=qwtotal
  441. else
  442. disksize:=-1;
  443. end
  444. else
  445. begin
  446. if GetDiskFreeSpace(@disk[1],secs,bytes,free,total) then
  447. disksize:=int64(total)*secs*bytes
  448. else
  449. disksize:=-1;
  450. end;
  451. end;
  452. Function GetCurrentDir : String;
  453. begin
  454. GetDir(0, result);
  455. end;
  456. Function SetCurrentDir (Const NewDir : String) : Boolean;
  457. begin
  458. Result:=SetCurrentDirectory(PChar(NewDir));
  459. end;
  460. Function CreateDir (Const NewDir : String) : Boolean;
  461. begin
  462. Result:=CreateDirectory(PChar(NewDir),nil);
  463. end;
  464. Function RemoveDir (Const Dir : String) : Boolean;
  465. begin
  466. Result:=RemoveDirectory(PChar(Dir));
  467. end;
  468. {****************************************************************************
  469. Time Functions
  470. ****************************************************************************}
  471. Procedure GetLocalTime(var SystemTime: TSystemTime);
  472. begin
  473. windows.Getlocaltime(SystemTime);
  474. end;
  475. function GetLocalTimeOffset: Integer;
  476. var
  477. TZInfo: TTimeZoneInformation;
  478. begin
  479. case GetTimeZoneInformation(TZInfo) of
  480. TIME_ZONE_ID_UNKNOWN:
  481. Result := TZInfo.Bias;
  482. TIME_ZONE_ID_STANDARD:
  483. Result := TZInfo.Bias + TZInfo.StandardBias;
  484. TIME_ZONE_ID_DAYLIGHT:
  485. Result := TZInfo.Bias + TZInfo.DaylightBias;
  486. else
  487. Result := 0;
  488. end;
  489. end;
  490. {****************************************************************************
  491. Misc Functions
  492. ****************************************************************************}
  493. procedure sysbeep;
  494. begin
  495. MessageBeep(0);
  496. end;
  497. {****************************************************************************
  498. Locale Functions
  499. ****************************************************************************}
  500. function GetLocaleStr(LID, LT: Longint; const Def: string): ShortString;
  501. var
  502. L: Integer;
  503. Buf: array[0..255] of Char;
  504. begin
  505. L := GetLocaleInfo(LID, LT, Buf, SizeOf(Buf));
  506. if L > 0 then
  507. SetString(Result, @Buf[0], L - 1)
  508. else
  509. Result := Def;
  510. end;
  511. function GetLocaleChar(LID, LT: Longint; Def: Char): Char;
  512. var
  513. Buf: array[0..3] of Char; // sdate allows 4 chars.
  514. begin
  515. if GetLocaleInfo(LID, LT, Buf, sizeof(buf)) > 0 then
  516. Result := Buf[0]
  517. else
  518. Result := Def;
  519. end;
  520. function ConvertEraString(Count ,Year,Month,Day : integer) : string;
  521. var
  522. ASystemTime: TSystemTime;
  523. buf: array[0..100] of char;
  524. ALCID : LCID;
  525. PriLangID : Word;
  526. SubLangID : Word;
  527. begin
  528. Result := ''; if (Count<=0) then exit;
  529. DateTimeToSystemTime(EncodeDate(Year,Month,Day),ASystemTime);
  530. ALCID := GetThreadLocale;
  531. // ALCID := SysLocale.DefaultLCID;
  532. if GetDateFormat(ALCID , DATE_USE_ALT_CALENDAR
  533. , @ASystemTime, PChar('gg')
  534. , @buf, SizeOf(buf)) > 0 then
  535. begin
  536. Result := buf;
  537. if Count = 1 then
  538. begin
  539. PriLangID := ALCID and $3FF;
  540. SubLangID := (ALCID and $FFFF) shr 10;
  541. case PriLangID of
  542. LANG_JAPANESE:
  543. begin
  544. Result := Copy(WideString(Result),1,1);
  545. end;
  546. LANG_CHINESE:
  547. if (SubLangID = SUBLANG_CHINESE_TRADITIONAL) then
  548. begin
  549. Result := Copy(WideString(Result),1,1);
  550. end;
  551. end;
  552. end;
  553. end;
  554. // if Result = '' then Result := StringOfChar('G',Count);
  555. end;
  556. function ConvertEraYearString(Count ,Year,Month,Day : integer) : string;
  557. var
  558. ALCID : LCID;
  559. ASystemTime : TSystemTime;
  560. AFormatText : string;
  561. buf : array[0..100] of Char;
  562. begin
  563. Result := '';
  564. DateTimeToSystemTime(EncodeDate(Year,Month,Day),ASystemTime);
  565. if Count <= 2 then
  566. AFormatText := 'yy'
  567. else
  568. AFormatText := 'yyyy';
  569. ALCID := GetThreadLocale;
  570. // ALCID := SysLocale.DefaultLCID;
  571. if GetDateFormat(ALCID, DATE_USE_ALT_CALENDAR
  572. , @ASystemTime, PChar(AFormatText)
  573. , @buf, SizeOf(buf)) > 0 then
  574. begin
  575. Result := buf;
  576. if (Count = 1) and (Result[1] = '0') then
  577. Result := Copy(Result, 2, Length(Result)-1);
  578. end;
  579. end;
  580. Function GetLocaleInt(LID,TP,Def: LongInt): LongInt;
  581. Var
  582. S: String;
  583. C: Integer;
  584. Begin
  585. S:=GetLocaleStr(LID,TP,'0');
  586. Val(S,Result,C);
  587. If C<>0 Then
  588. Result:=Def;
  589. End;
  590. function EnumEraNames(Names: PChar): WINBOOL; stdcall;
  591. var
  592. i : integer;
  593. begin
  594. Result := False;
  595. for i := Low(EraNames) to High(EraNames) do
  596. if (EraNames[i] = '') then
  597. begin
  598. EraNames[i] := Names;
  599. Result := True;
  600. break;
  601. end;
  602. end;
  603. function EnumEraYearOffsets(YearOffsets: PChar): WINBOOL; stdcall;
  604. var
  605. i : integer;
  606. begin
  607. Result := False;
  608. for i := Low(EraYearOffsets) to High(EraYearOffsets) do
  609. if (EraYearOffsets[i] = -1) then
  610. begin
  611. EraYearOffsets[i] := StrToIntDef(YearOffsets, 0);
  612. Result := True;
  613. break;
  614. end;
  615. end;
  616. procedure GetEraNamesAndYearOffsets;
  617. var
  618. ACALID : CALID;
  619. ALCID : LCID;
  620. buf : array[0..10] of char;
  621. i : integer;
  622. begin
  623. for i:= 1 to MaxEraCount do
  624. begin
  625. EraNames[i] := ''; EraYearOffsets[i] := -1;
  626. end;
  627. ALCID := GetThreadLocale;
  628. if GetLocaleInfo(ALCID , LOCALE_IOPTIONALCALENDAR, buf, sizeof(buf)) <= 0 then exit;
  629. ACALID := StrToIntDef(buf,1);
  630. if ACALID in [3..5] then
  631. begin
  632. EnumCalendarInfoA(@EnumEraNames, ALCID, ACALID , CAL_SERASTRING);
  633. EnumCalendarInfoA(@EnumEraYearOffsets, ALCID, ACALID, CAL_IYEAROFFSETRANGE);
  634. end;
  635. (*
  636. 1 CAL_GREGORIAN Gregorian (localized)
  637. 2 CAL_GREGORIAN_US Gregorian (English strings always)
  638. 3 CAL_JAPAN Japanese Emperor Era
  639. 4 CAL_TAIWAN Taiwan Calendar
  640. 5 CAL_KOREA Korean Tangun Era
  641. 6 CAL_HIJRI Hijri (Arabic Lunar)
  642. 7 CAL_THAI Thai
  643. 8 CAL_HEBREW Hebrew (Lunar)
  644. 9 CAL_GREGORIAN_ME_FRENCH Gregorian Middle East French
  645. 10 CAL_GREGORIAN_ARABIC Gregorian Arabic
  646. 11 CAL_GREGORIAN_XLIT_ENGLISH Gregorian transliterated English
  647. 12 CAL_GREGORIAN_XLIT_FRENCH Gregorian transliterated French
  648. 23 CAL_UMALQURA Windows Vista or later: Um Al Qura (Arabic lunar) calendar
  649. *)
  650. end;
  651. procedure GetLocaleFormatSettings(LCID: Integer; var FormatSettings: TFormatSettings);
  652. var
  653. HF : Shortstring;
  654. LID : Windows.LCID;
  655. I,Day : longint;
  656. begin
  657. LID := LCID;
  658. with FormatSettings do
  659. begin
  660. { Date stuff }
  661. for I := 1 to 12 do
  662. begin
  663. ShortMonthNames[I]:=GetLocaleStr(LID,LOCALE_SABBREVMONTHNAME1+I-1,ShortMonthNames[i]);
  664. LongMonthNames[I]:=GetLocaleStr(LID,LOCALE_SMONTHNAME1+I-1,LongMonthNames[i]);
  665. end;
  666. for I := 1 to 7 do
  667. begin
  668. Day := (I + 5) mod 7;
  669. ShortDayNames[I]:=GetLocaleStr(LID,LOCALE_SABBREVDAYNAME1+Day,ShortDayNames[i]);
  670. LongDayNames[I]:=GetLocaleStr(LID,LOCALE_SDAYNAME1+Day,LongDayNames[i]);
  671. end;
  672. DateSeparator := GetLocaleChar(LID, LOCALE_SDATE, '/');
  673. ShortDateFormat := GetLocaleStr(LID, LOCALE_SSHORTDATE, 'm/d/yy');
  674. LongDateFormat := GetLocaleStr(LID, LOCALE_SLONGDATE, 'mmmm d, yyyy');
  675. { Time stuff }
  676. TimeSeparator := GetLocaleChar(LID, LOCALE_STIME, ':');
  677. TimeAMString := GetLocaleStr(LID, LOCALE_S1159, 'AM');
  678. TimePMString := GetLocaleStr(LID, LOCALE_S2359, 'PM');
  679. if StrToIntDef(GetLocaleStr(LID, LOCALE_ITLZERO, '0'), 0) = 0 then
  680. HF:='h'
  681. else
  682. HF:='hh';
  683. // No support for 12 hour stuff at the moment...
  684. ShortTimeFormat := HF+':nn';
  685. LongTimeFormat := HF + ':nn:ss';
  686. { Currency stuff }
  687. CurrencyString:=GetLocaleStr(LID, LOCALE_SCURRENCY, '');
  688. CurrencyFormat:=StrToIntDef(GetLocaleStr(LID, LOCALE_ICURRENCY, '0'), 0);
  689. NegCurrFormat:=StrToIntDef(GetLocaleStr(LID, LOCALE_INEGCURR, '0'), 0);
  690. { Number stuff }
  691. ThousandSeparator:=GetLocaleChar(LID, LOCALE_STHOUSAND, ',');
  692. DecimalSeparator:=GetLocaleChar(LID, LOCALE_SDECIMAL, '.');
  693. CurrencyDecimals:=StrToIntDef(GetLocaleStr(LID, LOCALE_ICURRDIGITS, '0'), 0);
  694. ListSeparator := GetLocaleChar(LID, LOCALE_SLIST, ',');
  695. end;
  696. end;
  697. procedure GetFormatSettings;
  698. begin
  699. GetlocaleFormatSettings(GetThreadLocale, DefaultFormatSettings);
  700. end;
  701. Procedure InitInternational;
  702. var
  703. { A call to GetSystemMetrics changes the value of the 8087 Control Word on
  704. Pentium4 with WinXP SP2 }
  705. old8087CW: word;
  706. DefaultCustomLocaleID : LCID; // typedef DWORD LCID;
  707. DefaultCustomLanguageID : Word; // typedef WORD LANGID;
  708. begin
  709. /// workaround for Windows 7 bug, see bug report #18574
  710. SetThreadLocale(GetUserDefaultLCID);
  711. InitInternationalGeneric;
  712. old8087CW:=Get8087CW;
  713. SysLocale.MBCS:=GetSystemMetrics(SM_DBCSENABLED)<>0;
  714. SysLocale.RightToLeft:=GetSystemMetrics(SM_MIDEASTENABLED)<>0;
  715. SysLocale.DefaultLCID := $0409;
  716. SysLocale.PriLangID := LANG_ENGLISH;
  717. SysLocale.SubLangID := SUBLANG_ENGLISH_US;
  718. // probably needs update with getthreadlocale. post 2.0.2
  719. DefaultCustomLocaleID := GetThreadLocale;
  720. if DefaultCustomLocaleID <> 0 then
  721. begin
  722. { Locale Identifiers
  723. +-------------+---------+-------------------------+
  724. | Reserved | Sort ID | Language ID |
  725. +-------------+---------+-------------------------+
  726. 31 20 19 16 15 0 bit }
  727. DefaultCustomLanguageID := DefaultCustomLocaleID and $FFFF; // 2^16
  728. if DefaultCustomLanguageID <> 0 then
  729. begin
  730. SysLocale.DefaultLCID := DefaultCustomLocaleID;
  731. { Language Identifiers
  732. +-------------------------+-------------------------+
  733. | SubLanguage ID | Primary Language ID |
  734. +-------------------------+-------------------------+
  735. 15 10 9 0 bit }
  736. SysLocale.PriLangID := DefaultCustomLanguageID and $3ff; // 2^10
  737. SysLocale.SubLangID := DefaultCustomLanguageID shr 10;
  738. end;
  739. end;
  740. Set8087CW(old8087CW);
  741. GetFormatSettings;
  742. if SysLocale.FarEast then GetEraNamesAndYearOffsets;
  743. end;
  744. {****************************************************************************
  745. Target Dependent
  746. ****************************************************************************}
  747. function SysErrorMessage(ErrorCode: Integer): String;
  748. const
  749. MaxMsgSize = Format_Message_Max_Width_Mask;
  750. var
  751. MsgBuffer: pChar;
  752. begin
  753. GetMem(MsgBuffer, MaxMsgSize);
  754. FillChar(MsgBuffer^, MaxMsgSize, #0);
  755. FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
  756. nil,
  757. ErrorCode,
  758. MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
  759. MsgBuffer, { This function allocs the memory }
  760. MaxMsgSize, { Maximum message size }
  761. nil);
  762. SysErrorMessage := StrPas(MsgBuffer);
  763. FreeMem(MsgBuffer, MaxMsgSize);
  764. end;
  765. {****************************************************************************
  766. Initialization code
  767. ****************************************************************************}
  768. {$push}
  769. { GetEnvironmentStrings cannot be checked by CheckPointer function }
  770. {$checkpointer off}
  771. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  772. var
  773. s : string;
  774. i : longint;
  775. hp,p : pchar;
  776. begin
  777. Result:='';
  778. p:=GetEnvironmentStrings;
  779. hp:=p;
  780. while hp^<>#0 do
  781. begin
  782. s:=strpas(hp);
  783. i:=pos('=',s);
  784. if uppercase(copy(s,1,i-1))=upcase(envvar) then
  785. begin
  786. Result:=copy(s,i+1,length(s)-i);
  787. break;
  788. end;
  789. { next string entry}
  790. hp:=hp+strlen(hp)+1;
  791. end;
  792. FreeEnvironmentStrings(p);
  793. end;
  794. Function GetEnvironmentVariableCount : Integer;
  795. var
  796. hp,p : pchar;
  797. begin
  798. Result:=0;
  799. p:=GetEnvironmentStrings;
  800. hp:=p;
  801. If (Hp<>Nil) then
  802. while hp^<>#0 do
  803. begin
  804. Inc(Result);
  805. hp:=hp+strlen(hp)+1;
  806. end;
  807. FreeEnvironmentStrings(p);
  808. end;
  809. Function GetEnvironmentString(Index : Integer) : String;
  810. var
  811. hp,p : pchar;
  812. begin
  813. Result:='';
  814. p:=GetEnvironmentStrings;
  815. hp:=p;
  816. If (Hp<>Nil) then
  817. begin
  818. while (hp^<>#0) and (Index>1) do
  819. begin
  820. Dec(Index);
  821. hp:=hp+strlen(hp)+1;
  822. end;
  823. If (hp^<>#0) then
  824. Result:=StrPas(HP);
  825. end;
  826. FreeEnvironmentStrings(p);
  827. end;
  828. {$pop}
  829. function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
  830. // win specific function
  831. var
  832. SI: TStartupInfo;
  833. PI: TProcessInformation;
  834. Proc : THandle;
  835. l : DWord;
  836. CommandLine : ansistring;
  837. e : EOSError;
  838. ExecInherits : longbool;
  839. begin
  840. FillChar(SI, SizeOf(SI), 0);
  841. SI.cb:=SizeOf(SI);
  842. SI.wShowWindow:=1;
  843. { always surround the name of the application by quotes
  844. so that long filenames will always be accepted. But don't
  845. do it if there are already double quotes, since Win32 does not
  846. like double quotes which are duplicated!
  847. }
  848. if pos('"',path)=0 then
  849. CommandLine:='"'+path+'"'
  850. else
  851. CommandLine:=path;
  852. if ComLine <> '' then
  853. CommandLine:=Commandline+' '+ComLine+#0
  854. else
  855. CommandLine := CommandLine + #0;
  856. ExecInherits:=ExecInheritsHandles in Flags;
  857. if not CreateProcess(nil, pchar(CommandLine),
  858. Nil, Nil, ExecInherits,$20, Nil, Nil, SI, PI) then
  859. begin
  860. e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
  861. e.ErrorCode:=GetLastError;
  862. raise e;
  863. end;
  864. Proc:=PI.hProcess;
  865. if WaitForSingleObject(Proc, dword($ffffffff)) <> $ffffffff then
  866. begin
  867. GetExitCodeProcess(Proc,l);
  868. CloseHandle(Proc);
  869. CloseHandle(PI.hThread);
  870. result:=l;
  871. end
  872. else
  873. begin
  874. e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
  875. e.ErrorCode:=GetLastError;
  876. CloseHandle(Proc);
  877. CloseHandle(PI.hThread);
  878. raise e;
  879. end;
  880. end;
  881. function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString;Flags:TExecuteFlags=[]):integer;
  882. var
  883. CommandLine: AnsiString;
  884. I: integer;
  885. begin
  886. Commandline := '';
  887. for I := 0 to High (ComLine) do
  888. if Pos (' ', ComLine [I]) <> 0 then
  889. CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
  890. else
  891. CommandLine := CommandLine + ' ' + Comline [I];
  892. ExecuteProcess := ExecuteProcess (Path, CommandLine,Flags);
  893. end;
  894. Procedure Sleep(Milliseconds : Cardinal);
  895. begin
  896. Windows.Sleep(MilliSeconds)
  897. end;
  898. Function GetLastOSError : Integer;
  899. begin
  900. Result:=GetLastError;
  901. end;
  902. {****************************************************************************
  903. Initialization code
  904. ****************************************************************************}
  905. var
  906. kernel32dll : THandle;
  907. Procedure LoadVersionInfo;
  908. // and getfreespaceex
  909. Var
  910. versioninfo : TOSVERSIONINFO;
  911. begin
  912. GetDiskFreeSpaceEx:=nil;
  913. versioninfo.dwOSVersionInfoSize:=sizeof(versioninfo);
  914. GetVersionEx(versioninfo);
  915. Win32Platform:=versionInfo.dwPlatformId;
  916. Win32MajorVersion:=versionInfo.dwMajorVersion;
  917. Win32MinorVersion:=versionInfo.dwMinorVersion;
  918. Win32BuildNumber:=versionInfo.dwBuildNumber;
  919. Move (versioninfo.szCSDVersion ,Win32CSDVersion[1],128);
  920. win32CSDVersion[0]:=chr(strlen(pchar(@versioninfo.szCSDVersion)));
  921. kernel32dll:=GetModuleHandle('kernel32');
  922. if kernel32dll<>0 then
  923. GetDiskFreeSpaceEx:=TGetDiskFreeSpaceEx(GetProcAddress(kernel32dll,'GetDiskFreeSpaceExA'));
  924. end;
  925. Function GetAppConfigDir(Global : Boolean) : String;
  926. begin
  927. If Global then
  928. Result:=GetWindowsSpecialDir(CSIDL_COMMON_APPDATA)
  929. else
  930. Result:=GetWindowsSpecialDir(CSIDL_LOCAL_APPDATA);
  931. If (Result<>'') then
  932. begin
  933. if VendorName<>'' then
  934. Result:=IncludeTrailingPathDelimiter(Result+VendorName);
  935. Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
  936. end
  937. else
  938. Result:=IncludeTrailingPathDelimiter(DGetAppConfigDir(Global));
  939. end;
  940. Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
  941. begin
  942. result:=DGetAppConfigFile(Global,SubDir);
  943. end;
  944. Function GetUserDir : String;
  945. begin
  946. Result:=GetWindowsSpecialDir(CSIDL_PROFILE);
  947. end;
  948. Procedure InitSysConfigDir;
  949. begin
  950. SetLength(SysConfigDir, MAX_PATH);
  951. SetLength(SysConfigDir, GetWindowsDirectory(PChar(SysConfigDir), MAX_PATH));
  952. end;
  953. {****************************************************************************
  954. Target Dependent WideString stuff
  955. ****************************************************************************}
  956. { This is the case of Win9x. Limited to current locale of course, but it's better
  957. than not working at all. }
  958. function DoCompareStringA(P1, P2: PWideChar; L1, L2: PtrUInt; Flags: DWORD): PtrInt;
  959. var
  960. a1, a2: AnsiString;
  961. begin
  962. if L1>0 then
  963. widestringmanager.Wide2AnsiMoveProc(P1,a1,DefaultSystemCodePage,L1);
  964. if L2>0 then
  965. widestringmanager.Wide2AnsiMoveProc(P2,a2,DefaultSystemCodePage,L2);
  966. SetLastError(0);
  967. Result:=CompareStringA(LOCALE_USER_DEFAULT,Flags,pchar(a1),
  968. length(a1),pchar(a2),length(a2))-2;
  969. end;
  970. function DoCompareStringW(P1, P2: PWideChar; L1, L2: PtrUInt; Flags: DWORD): PtrInt;
  971. begin
  972. SetLastError(0);
  973. Result:=CompareStringW(LOCALE_USER_DEFAULT,Flags,P1,L1,P2,L2)-2;
  974. if GetLastError=0 then
  975. Exit;
  976. if GetLastError=ERROR_CALL_NOT_IMPLEMENTED then // Win9x case
  977. Result:=DoCompareStringA(P1, P2, L1, L2, Flags);
  978. if GetLastError<>0 then
  979. RaiseLastOSError;
  980. end;
  981. function Win32CompareWideString(const s1, s2 : WideString) : PtrInt;
  982. begin
  983. Result:=DoCompareStringW(PWideChar(s1), PWideChar(s2), Length(s1), Length(s2), 0);
  984. end;
  985. function Win32CompareTextWideString(const s1, s2 : WideString) : PtrInt;
  986. begin
  987. Result:=DoCompareStringW(PWideChar(s1), PWideChar(s2), Length(s1), Length(s2), NORM_IGNORECASE);
  988. end;
  989. function Win32AnsiUpperCase(const s: string): string;
  990. begin
  991. if length(s)>0 then
  992. begin
  993. result:=s;
  994. UniqueString(result);
  995. CharUpperBuff(pchar(result),length(result));
  996. end
  997. else
  998. result:='';
  999. end;
  1000. function Win32AnsiLowerCase(const s: string): string;
  1001. begin
  1002. if length(s)>0 then
  1003. begin
  1004. result:=s;
  1005. UniqueString(result);
  1006. CharLowerBuff(pchar(result),length(result));
  1007. end
  1008. else
  1009. result:='';
  1010. end;
  1011. function Win32AnsiCompareStr(const S1, S2: string): PtrInt;
  1012. begin
  1013. result:=CompareString(LOCALE_USER_DEFAULT,0,pchar(s1),length(s1),
  1014. pchar(s2),length(s2))-2;
  1015. end;
  1016. function Win32AnsiCompareText(const S1, S2: string): PtrInt;
  1017. begin
  1018. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,pchar(s1),length(s1),
  1019. pchar(s2),length(s2))-2;
  1020. end;
  1021. function Win32AnsiStrComp(S1, S2: PChar): PtrInt;
  1022. begin
  1023. result:=CompareString(LOCALE_USER_DEFAULT,0,s1,-1,s2,-1)-2;
  1024. end;
  1025. function Win32AnsiStrIComp(S1, S2: PChar): PtrInt;
  1026. begin
  1027. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,-1,s2,-1)-2;
  1028. end;
  1029. function Win32AnsiStrLComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  1030. begin
  1031. result:=CompareString(LOCALE_USER_DEFAULT,0,s1,maxlen,s2,maxlen)-2;
  1032. end;
  1033. function Win32AnsiStrLIComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  1034. begin
  1035. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,maxlen,s2,maxlen)-2;
  1036. end;
  1037. function Win32AnsiStrLower(Str: PChar): PChar;
  1038. begin
  1039. CharLower(str);
  1040. result:=str;
  1041. end;
  1042. function Win32AnsiStrUpper(Str: PChar): PChar;
  1043. begin
  1044. CharUpper(str);
  1045. result:=str;
  1046. end;
  1047. function Win32CompareUnicodeString(const s1, s2 : UnicodeString) : PtrInt;
  1048. begin
  1049. Result:=DoCompareStringW(PWideChar(s1), PWideChar(s2), Length(s1), Length(s2), 0);
  1050. end;
  1051. function Win32CompareTextUnicodeString(const s1, s2 : UnicodeString) : PtrInt;
  1052. begin
  1053. Result:=DoCompareStringW(PWideChar(s1), PWideChar(s2), Length(s1), Length(s2), NORM_IGNORECASE);
  1054. end;
  1055. { there is a similiar procedure in the system unit which inits the fields which
  1056. are relevant already for the system unit }
  1057. procedure InitWin32Widestrings;
  1058. begin
  1059. { return value: number of code points in the string. Whenever an invalid
  1060. code point is encountered, all characters part of this invalid code point
  1061. are considered to form one "character" and the next character is
  1062. considered to be the start of a new (possibly also invalid) code point }
  1063. //!!! CharLengthPCharProc : function(const Str: PChar): PtrInt;
  1064. { return value:
  1065. -1 if incomplete or invalid code point
  1066. 0 if NULL character,
  1067. > 0 if that's the length in bytes of the code point }
  1068. //!!!! CodePointLengthProc : function(const Str: PChar; MaxLookAead: PtrInt): Ptrint;
  1069. widestringmanager.CompareWideStringProc:=@Win32CompareWideString;
  1070. widestringmanager.CompareTextWideStringProc:=@Win32CompareTextWideString;
  1071. widestringmanager.UpperAnsiStringProc:=@Win32AnsiUpperCase;
  1072. widestringmanager.LowerAnsiStringProc:=@Win32AnsiLowerCase;
  1073. widestringmanager.CompareStrAnsiStringProc:=@Win32AnsiCompareStr;
  1074. widestringmanager.CompareTextAnsiStringProc:=@Win32AnsiCompareText;
  1075. widestringmanager.StrCompAnsiStringProc:=@Win32AnsiStrComp;
  1076. widestringmanager.StrICompAnsiStringProc:=@Win32AnsiStrIComp;
  1077. widestringmanager.StrLCompAnsiStringProc:=@Win32AnsiStrLComp;
  1078. widestringmanager.StrLICompAnsiStringProc:=@Win32AnsiStrLIComp;
  1079. widestringmanager.StrLowerAnsiStringProc:=@Win32AnsiStrLower;
  1080. widestringmanager.StrUpperAnsiStringProc:=@Win32AnsiStrUpper;
  1081. widestringmanager.CompareUnicodeStringProc:=@Win32CompareUnicodeString;
  1082. widestringmanager.CompareTextUnicodeStringProc:=@Win32CompareTextUnicodeString;
  1083. end;
  1084. { Platform-specific exception support }
  1085. function WinExceptionObject(code: Longint; const rec: TExceptionRecord): Exception;
  1086. var
  1087. entry: PExceptMapEntry;
  1088. begin
  1089. entry := FindExceptMapEntry(code);
  1090. if assigned(entry) then
  1091. result:=entry^.cls.CreateRes(entry^.msg)
  1092. else
  1093. result:=EExternalException.CreateResFmt(@SExternalException,[rec.ExceptionCode]);
  1094. if result is EExternal then
  1095. EExternal(result).FExceptionRecord:=rec;
  1096. end;
  1097. function WinExceptionClass(code: longint): ExceptClass;
  1098. var
  1099. entry: PExceptMapEntry;
  1100. begin
  1101. entry := FindExceptMapEntry(code);
  1102. if assigned(entry) then
  1103. result:=entry^.cls
  1104. else
  1105. result:=EExternalException;
  1106. end;
  1107. Initialization
  1108. InitWin32Widestrings;
  1109. InitExceptions; { Initialize exceptions. OS independent }
  1110. {$ifdef win64} { Nothing win64-specific here, just keeping exe size down
  1111. as these procedures aren't used in generic exception handling }
  1112. ExceptObjProc:=@WinExceptionObject;
  1113. ExceptClsProc:=@WinExceptionClass;
  1114. {$endif win64}
  1115. InitInternational; { Initialize internationalization settings }
  1116. LoadVersionInfo;
  1117. InitSysConfigDir;
  1118. OnBeep:=@SysBeep;
  1119. Finalization
  1120. DoneExceptions;
  1121. end.