syswin.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2008 by Florian Klaempfl and Pavel Ozerski
  4. member of the Free Pascal development team.
  5. FPC Pascal system unit part shared by win32/win64.
  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. {
  13. Error code definitions for the Win32 API functions
  14. Values are 32 bit values layed out as follows:
  15. 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  16. 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  17. +---+-+-+-----------------------+-------------------------------+
  18. |Sev|C|R| Facility | Code |
  19. +---+-+-+-----------------------+-------------------------------+
  20. where
  21. Sev - is the severity code
  22. 00 - Success
  23. 01 - Informational
  24. 10 - Warning
  25. 11 - Error
  26. C - is the Customer code flag
  27. R - is a reserved bit
  28. Facility - is the facility code
  29. Code - is the facility's status code
  30. }
  31. const
  32. SEVERITY_SUCCESS = $00000000;
  33. SEVERITY_INFORMATIONAL = $40000000;
  34. SEVERITY_WARNING = $80000000;
  35. SEVERITY_ERROR = $C0000000;
  36. const
  37. STATUS_SEGMENT_NOTIFICATION = $40000005;
  38. DBG_TERMINATE_THREAD = $40010003;
  39. DBG_TERMINATE_PROCESS = $40010004;
  40. DBG_CONTROL_C = $40010005;
  41. DBG_CONTROL_BREAK = $40010008;
  42. STATUS_GUARD_PAGE_VIOLATION = $80000001;
  43. STATUS_DATATYPE_MISALIGNMENT = $80000002;
  44. STATUS_BREAKPOINT = $80000003;
  45. STATUS_SINGLE_STEP = $80000004;
  46. DBG_EXCEPTION_NOT_HANDLED = $80010001;
  47. STATUS_ACCESS_VIOLATION = $C0000005;
  48. STATUS_IN_PAGE_ERROR = $C0000006;
  49. STATUS_INVALID_HANDLE = $C0000008;
  50. STATUS_NO_MEMORY = $C0000017;
  51. STATUS_ILLEGAL_INSTRUCTION = $C000001D;
  52. STATUS_NONCONTINUABLE_EXCEPTION = $C0000025;
  53. STATUS_INVALID_DISPOSITION = $C0000026;
  54. STATUS_ARRAY_BOUNDS_EXCEEDED = $C000008C;
  55. STATUS_FLOAT_DENORMAL_OPERAND = $C000008D;
  56. STATUS_FLOAT_DIVIDE_BY_ZERO = $C000008E;
  57. STATUS_FLOAT_INEXACT_RESULT = $C000008F;
  58. STATUS_FLOAT_INVALID_OPERATION = $C0000090;
  59. STATUS_FLOAT_OVERFLOW = $C0000091;
  60. STATUS_FLOAT_STACK_CHECK = $C0000092;
  61. STATUS_FLOAT_UNDERFLOW = $C0000093;
  62. STATUS_INTEGER_DIVIDE_BY_ZERO = $C0000094;
  63. STATUS_INTEGER_OVERFLOW = $C0000095;
  64. STATUS_PRIVILEGED_INSTRUCTION = $C0000096;
  65. STATUS_STACK_OVERFLOW = $C00000FD;
  66. STATUS_CONTROL_C_EXIT = $C000013A;
  67. STATUS_FLOAT_MULTIPLE_FAULTS = $C00002B4;
  68. STATUS_FLOAT_MULTIPLE_TRAPS = $C00002B5;
  69. STATUS_REG_NAT_CONSUMPTION = $C00002C9;
  70. { Exceptions raised by RTL use this code }
  71. FPC_EXCEPTION_CODE = $E0465043;
  72. EXCEPTION_EXECUTE_HANDLER = 1;
  73. EXCEPTION_CONTINUE_EXECUTION = -1;
  74. EXCEPTION_CONTINUE_SEARCH = 0;
  75. { exception flags (not everything applies to Win32!) }
  76. EXCEPTION_NONCONTINUABLE = $01;
  77. EXCEPTION_UNWINDING = $02;
  78. EXCEPTION_EXIT_UNWIND = $04;
  79. EXCEPTION_STACK_INVALID = $08;
  80. EXCEPTION_NESTED_CALL = $10;
  81. EXCEPTION_TARGET_UNWIND = $20;
  82. EXCEPTION_COLLIDED_UNWIND = $40;
  83. CONTEXT_X86 = $00010000;
  84. CONTEXT_CONTROL = CONTEXT_X86 or $00000001;
  85. CONTEXT_INTEGER = CONTEXT_X86 or $00000002;
  86. CONTEXT_SEGMENTS = CONTEXT_X86 or $00000004;
  87. CONTEXT_FLOATING_POINT = CONTEXT_X86 or $00000008;
  88. CONTEXT_DEBUG_REGISTERS = CONTEXT_X86 or $00000010;
  89. CONTEXT_EXTENDED_REGISTERS = CONTEXT_X86 or $00000020;
  90. CONTEXT_FULL = CONTEXT_CONTROL or CONTEXT_INTEGER or CONTEXT_SEGMENTS;
  91. MAXIMUM_SUPPORTED_EXTENSION = 512;
  92. type
  93. EXCEPTION_DISPOSITION=(
  94. ExceptionContinueExecution,
  95. ExceptionContinueSearch,
  96. ExceptionNestedException,
  97. ExceptionCollidedUnwind
  98. );
  99. TUnwindProc=procedure(frame: PtrUInt);
  100. procedure RaiseException(
  101. dwExceptionCode: DWORD;
  102. dwExceptionFlags: DWORD;
  103. dwArgCount: DWORD;
  104. lpArguments: Pointer); // msdn: *ULONG_PTR
  105. stdcall; external 'kernel32.dll' name 'RaiseException';
  106. {*****************************************************************************
  107. Parameter Handling
  108. *****************************************************************************}
  109. procedure setup_arguments;
  110. var
  111. arglen,
  112. count : longint;
  113. argstart,
  114. pc,arg : pchar;
  115. quote : Boolean;
  116. argvlen : longint;
  117. buf: array[0..259] of char; // need MAX_PATH bytes, not 256!
  118. procedure allocarg(idx,len:longint);
  119. var
  120. oldargvlen : longint;
  121. begin
  122. if idx>=argvlen then
  123. begin
  124. oldargvlen:=argvlen;
  125. argvlen:=(idx+8) and (not 7);
  126. sysreallocmem(argv,argvlen*sizeof(pointer));
  127. fillchar(argv[oldargvlen],(argvlen-oldargvlen)*sizeof(pointer),0);
  128. end;
  129. { use realloc to reuse already existing memory }
  130. { always allocate, even if length is zero, since }
  131. { the arg. is still present! }
  132. sysreallocmem(argv[idx],len+1);
  133. end;
  134. begin
  135. { create commandline, it starts with the executed filename which is argv[0] }
  136. { Win32 passes the command NOT via the args, but via getmodulefilename}
  137. count:=0;
  138. argv:=nil;
  139. argvlen:=0;
  140. ArgLen := GetModuleFileName(0, @buf[0], sizeof(buf));
  141. buf[ArgLen] := #0; // be safe
  142. allocarg(0,arglen);
  143. move(buf,argv[0]^,arglen+1);
  144. { Setup cmdline variable }
  145. cmdline:=GetCommandLine;
  146. { process arguments }
  147. pc:=cmdline;
  148. {$IfDef SYSTEM_DEBUG_STARTUP}
  149. Writeln(stderr,'Win32 GetCommandLine is #',pc,'#');
  150. {$EndIf }
  151. while pc^<>#0 do
  152. begin
  153. { skip leading spaces }
  154. while pc^ in [#1..#32] do
  155. inc(pc);
  156. if pc^=#0 then
  157. break;
  158. { calc argument length }
  159. quote:=False;
  160. argstart:=pc;
  161. arglen:=0;
  162. while (pc^<>#0) do
  163. begin
  164. case pc^ of
  165. #1..#32 :
  166. begin
  167. if quote then
  168. inc(arglen)
  169. else
  170. break;
  171. end;
  172. '"' :
  173. if pc[1]<>'"' then
  174. quote := not quote
  175. else
  176. inc(pc);
  177. else
  178. inc(arglen);
  179. end;
  180. inc(pc);
  181. end;
  182. { copy argument }
  183. { Don't copy the first one, it is already there.}
  184. If Count<>0 then
  185. begin
  186. allocarg(count,arglen);
  187. quote:=False;
  188. pc:=argstart;
  189. arg:=argv[count];
  190. while (pc^<>#0) do
  191. begin
  192. case pc^ of
  193. #1..#32 :
  194. begin
  195. if quote then
  196. begin
  197. arg^:=pc^;
  198. inc(arg);
  199. end
  200. else
  201. break;
  202. end;
  203. '"' :
  204. if pc[1]<>'"' then
  205. quote := not quote
  206. else
  207. inc(pc);
  208. else
  209. begin
  210. arg^:=pc^;
  211. inc(arg);
  212. end;
  213. end;
  214. inc(pc);
  215. end;
  216. arg^:=#0;
  217. end;
  218. {$IfDef SYSTEM_DEBUG_STARTUP}
  219. Writeln(stderr,'dos arg ',count,' #',arglen,'#',argv[count],'#');
  220. {$EndIf SYSTEM_DEBUG_STARTUP}
  221. inc(count);
  222. end;
  223. { get argc }
  224. argc:=count;
  225. { free unused memory, leaving a nil entry at the end }
  226. sysreallocmem(argv,(count+1)*sizeof(pointer));
  227. argv[count] := nil;
  228. end;
  229. function paramcount : longint;
  230. begin
  231. paramcount := argc - 1;
  232. end;
  233. function paramstr(l : longint) : string;
  234. begin
  235. if (l>=0) and (l<argc) then
  236. paramstr:=strpas(argv[l])
  237. else
  238. paramstr:='';
  239. end;
  240. procedure randomize;
  241. begin
  242. randseed:=GetTickCount;
  243. end;
  244. Var
  245. DLLInitState : Longint = -1;
  246. DLLBuf : Jmp_buf;
  247. function Dll_entry{$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}(const info : TEntryInformation){$endif FPC_HAS_INDIRECT_MAIN_INFORMATION} : longbool; [public,alias:'_FPC_DLL_Entry'];
  248. begin
  249. {$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
  250. EntryInformation:=info;
  251. {$endif FPC_HAS_INDIRECT_MAIN_INFORMATION}
  252. IsLibrary:=true;
  253. DllInitState:=DLLreason;
  254. Dll_entry:=false; { return value is ignored, except when DLLreason=DLL_PROCESS_ATTACH }
  255. case DLLreason of
  256. DLL_PROCESS_ATTACH :
  257. begin
  258. MainThreadIdWin32 := Win32GetCurrentThreadId;
  259. If SetJmp(DLLBuf) = 0 then
  260. begin
  261. {$ifdef FPC_HAS_INDIRECT_MAIN_INFORMATION}
  262. EntryInformation.PascalMain();
  263. {$else FPC_HAS_INDIRECT_MAIN_INFORMATION}
  264. PascalMain;
  265. {$endif FPC_HAS_INDIRECT_MAIN_INFORMATION}
  266. Dll_entry:=true;
  267. end
  268. else
  269. Dll_entry:=(ExitCode=0);
  270. end;
  271. DLL_THREAD_ATTACH :
  272. begin
  273. { SysInitMultithreading must not be called here,
  274. see comments in exec_tls_callback below }
  275. { Allocate Threadvars }
  276. SysAllocateThreadVars;
  277. { NS : no idea what is correct to pass here - pass dummy value for now }
  278. { passing a dummy is ok, the correct value is read from the coff header of SysInstance (FK) }
  279. InitThread($1000000); { Assume everything is idempotent there, as the thread could have been created with BeginThread... }
  280. if assigned(Dll_Thread_Attach_Hook) then
  281. Dll_Thread_Attach_Hook(DllParam);
  282. end;
  283. DLL_THREAD_DETACH :
  284. begin
  285. if assigned(Dll_Thread_Detach_Hook) then
  286. Dll_Thread_Detach_Hook(DllParam);
  287. { Release Threadvars }
  288. if TlsGetValue(TLSKey)<>nil then
  289. DoneThread; { Assume everything is idempotent there }
  290. end;
  291. DLL_PROCESS_DETACH :
  292. begin
  293. if MainThreadIDWin32=0 then // already been here.
  294. exit;
  295. If SetJmp(DLLBuf) = 0 then
  296. begin
  297. if assigned(Dll_Process_Detach_Hook) then
  298. Dll_Process_Detach_Hook(DllParam);
  299. InternalExit;
  300. end;
  301. SysReleaseThreadVars;
  302. { Free TLS resources used by ThreadVars }
  303. SysFiniMultiThreading;
  304. MainThreadIDWin32:=0;
  305. end;
  306. end;
  307. DllInitState:=-1;
  308. end;
  309. {****************************************************************************
  310. Error Message writing using messageboxes
  311. ****************************************************************************}
  312. function MessageBox(w1:longint;l1,l2:pointer;w2:longint):longint;
  313. stdcall;external 'user32' name 'MessageBoxA';
  314. const
  315. ErrorBufferLength = 1024;
  316. var
  317. ErrorBuf : array[0..ErrorBufferLength] of char;
  318. ErrorLen : SizeInt;
  319. Function ErrorWrite(Var F: TextRec): Integer;
  320. {
  321. An error message should always end with #13#10#13#10
  322. }
  323. var
  324. i : SizeInt;
  325. Begin
  326. while F.BufPos>0 do
  327. begin
  328. begin
  329. if F.BufPos+ErrorLen>ErrorBufferLength then
  330. i:=ErrorBufferLength-ErrorLen
  331. else
  332. i:=F.BufPos;
  333. Move(F.BufPtr^,ErrorBuf[ErrorLen],i);
  334. inc(ErrorLen,i);
  335. ErrorBuf[ErrorLen]:=#0;
  336. end;
  337. if ErrorLen=ErrorBufferLength then
  338. begin
  339. MessageBox(0,@ErrorBuf,pchar('Error'),0);
  340. ErrorLen:=0;
  341. end;
  342. Dec(F.BufPos,i);
  343. end;
  344. ErrorWrite:=0;
  345. End;
  346. Function ErrorClose(Var F: TextRec): Integer;
  347. begin
  348. if ErrorLen>0 then
  349. begin
  350. MessageBox(0,@ErrorBuf,pchar('Error'),0);
  351. ErrorLen:=0;
  352. end;
  353. ErrorLen:=0;
  354. ErrorClose:=0;
  355. end;
  356. Function ErrorOpen(Var F: TextRec): Integer;
  357. Begin
  358. TextRec(F).InOutFunc:=@ErrorWrite;
  359. TextRec(F).FlushFunc:=@ErrorWrite;
  360. TextRec(F).CloseFunc:=@ErrorClose;
  361. ErrorLen:=0;
  362. ErrorOpen:=0;
  363. End;
  364. procedure AssignError(Var T: Text);
  365. begin
  366. Assign(T,'');
  367. TextRec(T).OpenFunc:=@ErrorOpen;
  368. Rewrite(T);
  369. end;
  370. procedure SysInitStdIO;
  371. begin
  372. { Setup stdin, stdout and stderr, for GUI apps redirect stderr,stdout to be
  373. displayed in a messagebox }
  374. StdInputHandle:=longint(GetStdHandle(cardinal(STD_INPUT_HANDLE)));
  375. StdOutputHandle:=longint(GetStdHandle(cardinal(STD_OUTPUT_HANDLE)));
  376. StdErrorHandle:=longint(GetStdHandle(cardinal(STD_ERROR_HANDLE)));
  377. if not IsConsole then
  378. begin
  379. AssignError(stderr);
  380. AssignError(StdOut);
  381. Assign(Output,'');
  382. Assign(Input,'');
  383. Assign(ErrOutput,'');
  384. end
  385. else
  386. begin
  387. OpenStdIO(Input,fmInput,StdInputHandle);
  388. OpenStdIO(Output,fmOutput,StdOutputHandle);
  389. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  390. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  391. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  392. end;
  393. end;
  394. { ProcessID cached to avoid repeated calls to GetCurrentProcess. }
  395. var
  396. ProcessID: SizeUInt;
  397. function GetProcessID: SizeUInt;
  398. begin
  399. GetProcessID := ProcessID;
  400. end;
  401. {******************************************************************************
  402. Unicode
  403. ******************************************************************************}
  404. const
  405. { MultiByteToWideChar }
  406. MB_PRECOMPOSED = 1;
  407. WC_NO_BEST_FIT_CHARS = $400;
  408. function MultiByteToWideChar(CodePage:UINT; dwFlags:DWORD; lpMultiByteStr:PChar; cchMultiByte:longint; lpWideCharStr:PWideChar;cchWideChar:longint):longint;
  409. stdcall; external 'kernel32' name 'MultiByteToWideChar';
  410. function WideCharToMultiByte(CodePage:UINT; dwFlags:DWORD; lpWideCharStr:PWideChar; cchWideChar:longint; lpMultiByteStr:PChar;cchMultiByte:longint; lpDefaultChar:PChar; lpUsedDefaultChar:pointer):longint;
  411. stdcall; external 'kernel32' name 'WideCharToMultiByte';
  412. function CharUpperBuff(lpsz:LPWSTR; cchLength:DWORD):DWORD;
  413. stdcall; external 'user32' name 'CharUpperBuffW';
  414. function CharLowerBuff(lpsz:LPWSTR; cchLength:DWORD):DWORD;
  415. stdcall; external 'user32' name 'CharLowerBuffW';
  416. procedure Win32Unicode2AnsiMove(source:punicodechar;var dest:RawByteString;cp : TSystemCodePage;len:SizeInt);
  417. var
  418. destlen: SizeInt;
  419. begin
  420. // retrieve length including trailing #0
  421. // not anymore, because this must also be usable for single characters
  422. destlen:=WideCharToMultiByte(cp, 0, source, len, nil, 0, nil, nil);
  423. // this will null-terminate
  424. setlength(dest, destlen);
  425. if destlen>0 then
  426. begin
  427. WideCharToMultiByte(cp, 0, source, len, @dest[1], destlen, nil, nil);
  428. PAnsiRec(pointer(dest)-AnsiFirstOff)^.CodePage:=cp;
  429. end;
  430. end;
  431. procedure Win32Ansi2UnicodeMove(source:pchar;cp : TSystemCodePage;var dest:UnicodeString;len:SizeInt);
  432. var
  433. destlen: SizeInt;
  434. dwflags: DWORD;
  435. begin
  436. // retrieve length including trailing #0
  437. // not anymore, because this must also be usable for single characters
  438. if cp=CP_UTF8 then
  439. dwFlags:=0
  440. else
  441. dwFlags:=MB_PRECOMPOSED;
  442. destlen:=MultiByteToWideChar(cp, dwFlags, source, len, nil, 0);
  443. // this will null-terminate
  444. setlength(dest, destlen);
  445. if destlen>0 then
  446. begin
  447. MultiByteToWideChar(cp, dwFlags, source, len, @dest[1], destlen);
  448. PUnicodeRec(pointer(dest)-UnicodeFirstOff)^.CodePage:=CP_UTF16;
  449. end;
  450. end;
  451. function Win32UnicodeUpper(const s : UnicodeString) : UnicodeString;
  452. begin
  453. result:=s;
  454. UniqueString(result);
  455. if length(result)>0 then
  456. CharUpperBuff(LPWSTR(result),length(result));
  457. end;
  458. function Win32UnicodeLower(const s : UnicodeString) : UnicodeString;
  459. begin
  460. result:=s;
  461. UniqueString(result);
  462. if length(result)>0 then
  463. CharLowerBuff(LPWSTR(result),length(result));
  464. end;
  465. {******************************************************************************
  466. Widestring
  467. ******************************************************************************}
  468. procedure Win32Ansi2WideMove(source:pchar;cp : TSystemCodePage;var dest:widestring;len:SizeInt);
  469. var
  470. destlen: SizeInt;
  471. dwFlags: DWORD;
  472. begin
  473. // retrieve length including trailing #0
  474. // not anymore, because this must also be usable for single characters
  475. if cp=CP_UTF8 then
  476. dwFlags:=0
  477. else
  478. dwFlags:=MB_PRECOMPOSED;
  479. destlen:=MultiByteToWideChar(cp, dwFlags, source, len, nil, 0);
  480. // this will null-terminate
  481. setlength(dest, destlen);
  482. if destlen>0 then
  483. MultiByteToWideChar(cp, dwFlags, source, len, @dest[1], destlen);
  484. end;
  485. function Win32WideUpper(const s : WideString) : WideString;
  486. begin
  487. result:=s;
  488. if length(result)>0 then
  489. CharUpperBuff(LPWSTR(result),length(result));
  490. end;
  491. function Win32WideLower(const s : WideString) : WideString;
  492. begin
  493. result:=s;
  494. if length(result)>0 then
  495. CharLowerBuff(LPWSTR(result),length(result));
  496. end;
  497. type
  498. PWStrInitEntry = ^TWStrInitEntry;
  499. TWStrInitEntry = record
  500. addr: PPointer;
  501. data: Pointer;
  502. end;
  503. PWStrInitTablesTable = ^TWStrInitTablesTable;
  504. TWStrInitTablesTable = packed record
  505. count : longint;
  506. tables : packed array [1..32767] of PWStrInitEntry;
  507. end;
  508. {$if not(defined(VER2_2) or defined(VER2_4))}
  509. var
  510. WStrInitTablesTable: TWStrInitTablesTable; external name 'FPC_WIDEINITTABLES';
  511. {$endif}
  512. function GetACP:UINT; stdcall; external 'kernel32' name 'GetACP';
  513. function GetConsoleCP:UINT; stdcall; external 'kernel32' name 'GetConsoleCP';
  514. function Win32GetStandardCodePage(const stdcp: TStandardCodePageEnum): TSystemCodePage;
  515. begin
  516. case stdcp of
  517. scpAnsi,
  518. scpFileSystemSingleByte: Result := GetACP;
  519. scpConsoleInput: Result := GetConsoleCP;
  520. scpConsoleOutput: Result := GetConsoleOutputCP;
  521. end;
  522. end;
  523. { there is a similiar procedure in sysutils which inits the fields which
  524. are only relevant for the sysutils units }
  525. procedure InitWin32Widestrings;
  526. var
  527. i: longint;
  528. ptable: PWStrInitEntry;
  529. begin
  530. {$if not(defined(VER2_2) or defined(VER2_4))}
  531. { assign initial values to global Widestring typed consts }
  532. for i:=1 to WStrInitTablesTable.count do
  533. begin
  534. ptable:=WStrInitTablesTable.tables[i];
  535. while Assigned(ptable^.addr) do
  536. begin
  537. fpc_widestr_assign(ptable^.addr^, ptable^.data);
  538. Inc(ptable);
  539. end;
  540. end;
  541. {$endif}
  542. { Note: since WideChar=UnicodeChar and PWideChar=PUnicodeChar,
  543. Wide2AnsiMoveProc is identical to Unicode2AnsiStrMoveProc. }
  544. { Widestring }
  545. widestringmanager.Wide2AnsiMoveProc:=@Win32Unicode2AnsiMove;
  546. widestringmanager.Ansi2WideMoveProc:=@Win32Ansi2WideMove;
  547. widestringmanager.UpperWideStringProc:=@Win32WideUpper;
  548. widestringmanager.LowerWideStringProc:=@Win32WideLower;
  549. { Unicode }
  550. widestringmanager.Unicode2AnsiMoveProc:=@Win32Unicode2AnsiMove;
  551. widestringmanager.Ansi2UnicodeMoveProc:=@Win32Ansi2UnicodeMove;
  552. widestringmanager.UpperUnicodeStringProc:=@Win32UnicodeUpper;
  553. widestringmanager.LowerUnicodeStringProc:=@Win32UnicodeLower;
  554. { Codepage }
  555. widestringmanager.GetStandardCodePageProc:=@Win32GetStandardCodePage;
  556. DefaultSystemCodePage:=GetACP;
  557. DefaultUnicodeCodePage:=CP_UTF16;
  558. DefaultFileSystemCodePage:=DefaultSystemCodePage;
  559. DefaultRTLFileSystemCodePage:=DefaultFileSystemCodePage;
  560. end;