syswin32.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993-98 by Florian Klaempfl and Pavel Ozerski
  5. member of the Free Pascal development team.
  6. FPC Pascal system unit for the Win32 API.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$S-}
  14. unit syswin32;
  15. {$I os.inc}
  16. {.$DEFINE WINHEAP} { Use windows heap manager, if not set use FPC heap }
  17. interface
  18. { include system-independent routine headers }
  19. {$I systemh.inc}
  20. {$ifndef WinHeap}
  21. { include heap support headers }
  22. {$I heaph.inc}
  23. {$endif}
  24. const
  25. { Default filehandles }
  26. UnusedHandle : longint = -1;
  27. StdInputHandle : longint = 0;
  28. StdOutputHandle : longint = 0;
  29. StdErrorHandle : longint = 0;
  30. type
  31. TStartupInfo=packed record
  32. cb : longint;
  33. lpReserved : Pointer;
  34. lpDesktop : Pointer;
  35. lpTitle : Pointer;
  36. dwX : longint;
  37. dwY : longint;
  38. dwXSize : longint;
  39. dwYSize : longint;
  40. dwXCountChars : longint;
  41. dwYCountChars : longint;
  42. dwFillAttribute : longint;
  43. dwFlags : longint;
  44. wShowWindow : Word;
  45. cbReserved2 : Word;
  46. lpReserved2 : Pointer;
  47. hStdInput : longint;
  48. hStdOutput : longint;
  49. hStdError : longint;
  50. end;
  51. var
  52. { C compatible arguments }
  53. argc : longint;
  54. argv : ppchar;
  55. { Win32 Info }
  56. startupinfo : tstartupinfo;
  57. hprevinst,
  58. hinstance,
  59. cmdshow : longint;
  60. {$ifdef WinHeap}
  61. var
  62. heaperror : pointer;
  63. function HeapSize:longint;
  64. {$endif}
  65. implementation
  66. { include system independent routines }
  67. {$I system.inc}
  68. { some declarations for Win32 API calls }
  69. {$I win32.inc}
  70. CONST
  71. { These constants are used for conversion of error codes }
  72. { from win32 i/o errors to tp i/o errors }
  73. { errors 1 to 18 are the same as in Turbo Pascal }
  74. { DO NOT MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING! }
  75. { The media is write protected. }
  76. ERROR_WRITE_PROTECT = 19;
  77. { The system cannot find the device specified. }
  78. ERROR_BAD_UNIT = 20;
  79. { The device is not ready. }
  80. ERROR_NOT_READY = 21;
  81. { The device does not recognize the command. }
  82. ERROR_BAD_COMMAND = 22;
  83. { Data error (cyclic redundancy check) }
  84. ERROR_CRC = 23;
  85. { The program issued a command but the }
  86. { command length is incorrect. }
  87. ERROR_BAD_LENGTH = 24;
  88. { The drive cannot locate a specific }
  89. { area or track on the disk. }
  90. ERROR_SEEK = 25;
  91. { The specified disk or diskette cannot be accessed. }
  92. ERROR_NOT_DOS_DISK = 26;
  93. { The drive cannot find the sector requested. }
  94. ERROR_SECTOR_NOT_FOUND = 27;
  95. { The printer is out of paper. }
  96. ERROR_OUT_OF_PAPER = 28;
  97. { The system cannot write to the specified device. }
  98. ERROR_WRITE_FAULT = 29;
  99. { The system cannot read from the specified device. }
  100. ERROR_READ_FAULT = 30;
  101. { A device attached to the system is not functioning.}
  102. ERROR_GEN_FAILURE = 31;
  103. { The process cannot access the file because }
  104. { it is being used by another process. }
  105. ERROR_SHARING_VIOLATION = 32;
  106. var
  107. errno : longint;
  108. { misc. functions }
  109. function GetLastError : DWORD;
  110. external 'kernel32' name 'GetLastError';
  111. function MessageBox(w1:longint;l1,l2:pointer;w2:longint):longint;
  112. external 'user32' name 'MessageBoxA';
  113. { time and date functions }
  114. function GetTickCount : longint;
  115. external 'kernel32' name 'GetTickCount';
  116. { process functions }
  117. procedure ExitProcess(uExitCode : UINT);
  118. external 'kernel32' name 'ExitProcess';
  119. Procedure Errno2InOutRes;
  120. Begin
  121. { DO NOT MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING }
  122. if (errno >= ERROR_WRITE_PROTECT) and (errno <= ERROR_GEN_FAILURE) THEN
  123. BEGIN
  124. { This is the offset to the Win32 to add to directly map }
  125. { to the DOS/TP compatible error codes when in this range }
  126. InOutRes := word(errno)+131;
  127. END
  128. else
  129. { This case is special }
  130. if errno=ERROR_SHARING_VIOLATION THEN
  131. BEGIN
  132. InOutRes :=5;
  133. END
  134. else
  135. { other error codes can directly be mapped }
  136. InOutRes := Word(errno);
  137. errno:=0;
  138. end;
  139. {$ifdef dummy}
  140. procedure int_stackcheck(stack_size:longint);[public,alias: 'STACKCHECK'];
  141. {
  142. called when trying to get local stack if the compiler directive $S
  143. is set this function must preserve esi !!!! because esi is set by
  144. the calling proc for methods it must preserve all registers !!
  145. With a 2048 byte safe area used to write to StdIo without crossing
  146. the stack boundary
  147. }
  148. begin
  149. asm
  150. pushl %eax
  151. pushl %ebx
  152. movl stack_size,%ebx
  153. addl $2048,%ebx
  154. movl %esp,%eax
  155. subl %ebx,%eax
  156. movl stacklimit,%ebx
  157. cmpl %eax,%ebx
  158. jae __short_on_stack
  159. popl %ebx
  160. popl %eax
  161. leave
  162. ret $4
  163. __short_on_stack:
  164. { can be usefull for error recovery !! }
  165. popl %ebx
  166. popl %eax
  167. end['EAX','EBX'];
  168. HandleError(202);
  169. end;
  170. {$endif dummy}
  171. procedure halt(errnum : byte);
  172. begin
  173. do_exit;
  174. ExitProcess(errnum);
  175. end;
  176. function paramcount : longint;
  177. begin
  178. paramcount := argc - 1;
  179. end;
  180. function paramstr(l : longint) : string;
  181. begin
  182. if (l>=0) and (l+1<=argc) then
  183. paramstr:=strpas(argv[l])
  184. else
  185. paramstr:='';
  186. end;
  187. procedure randomize;
  188. begin
  189. randseed:=GetTickCount;
  190. end;
  191. {*****************************************************************************
  192. Heap Management
  193. *****************************************************************************}
  194. {$ifdef WinHeap}
  195. {$i winheap.inc}
  196. {$else}
  197. { memory functions }
  198. function GlobalAlloc(mode,size:longint):longint;
  199. external 'kernel32' name 'GlobalAlloc';
  200. function GlobalReAlloc(mode,size:longint):longint;
  201. external 'kernel32' name 'GlobalReAlloc';
  202. function GlobalHandle(p:pointer):longint;
  203. external 'kernel32' name 'GlobalHandle';
  204. function GlobalLock(handle:longint):pointer;
  205. external 'kernel32' name 'GlobalLock';
  206. function GlobalUnlock(h:longint):longint;
  207. external 'kernel32' name 'GlobalUnlock';
  208. function GlobalFree(h:longint):longint;
  209. external 'kernel32' name 'GlobalFree';
  210. function GlobalSize(h:longint):longint;
  211. external 'kernel32' name 'GlobalSize';
  212. procedure GlobalMemoryStatus(p:pointer);
  213. external 'kernel32' name 'GlobalMemoryStatus';
  214. function LocalAlloc(uFlags : UINT;uBytes :UINT) : HLOCAL;
  215. external 'kernel32' name 'LocalAlloc';
  216. function LocalFree(hMem:HLOCAL):HLOCAL;
  217. external 'kernel32' name 'LocalFree';
  218. function Sbrk(size : longint):longint;
  219. var
  220. h,l : longint;
  221. begin
  222. h:=GlobalAlloc(258,size);
  223. l:=longint(GlobalLock(h));
  224. if l=0 then l:=-1;
  225. Writeln('new heap part at $',hexstr(l,8), ' size = ',GlobalSize(h));
  226. sbrk:=l;
  227. end;
  228. { include standard heap management }
  229. {$I heap.inc}
  230. {$endif WinHeap}
  231. {*****************************************************************************
  232. Low Level File Routines
  233. *****************************************************************************}
  234. function WriteFile(fh:longint;buf:pointer;len:longint;var loaded:longint;
  235. overlap:pointer):longint;
  236. external 'kernel32' name 'WriteFile';
  237. function ReadFile(fh:longint;buf:pointer;len:longint;var loaded:longint;
  238. overlap:pointer):longint;
  239. external 'kernel32' name 'ReadFile';
  240. function CloseHandle(h : longint) : longint;
  241. external 'kernel32' name 'CloseHandle';
  242. function DeleteFile(p : pchar) : longint;
  243. external 'kernel32' name 'DeleteFileA';
  244. function MoveFile(old,_new : pchar) : longint;
  245. external 'kernel32' name 'MoveFileA';
  246. function SetFilePointer(l1,l2 : longint;l3 : pointer;l4 : longint) : longint;
  247. external 'kernel32' name 'SetFilePointer';
  248. function GetFileSize(h:longint;p:pointer) : longint;
  249. external 'kernel32' name 'GetFileSize';
  250. function CreateFile(name : pointer;access,sharing : longint;
  251. security : pointer;how,attr,template : longint) : longint;
  252. external 'kernel32' name 'CreateFileA';
  253. function SetEndOfFile(h : longint) : boolean;
  254. external 'kernel32' name 'SetEndOfFile';
  255. function GetFileType(Handle:DWORD):DWord;
  256. external 'kernel32' name 'GetFileType';
  257. procedure AllowSlash(p:pchar);
  258. var
  259. i : longint;
  260. begin
  261. { allow slash as backslash }
  262. for i:=0 to strlen(p) do
  263. if p[i]='/' then p[i]:='\';
  264. end;
  265. procedure do_close(h : longint);
  266. begin
  267. closehandle(h);
  268. end;
  269. procedure do_erase(p : pchar);
  270. begin
  271. AllowSlash(p);
  272. if DeleteFile(p)=0 then
  273. Begin
  274. errno:=GetLastError;
  275. Errno2InoutRes;
  276. end;
  277. end;
  278. procedure do_rename(p1,p2 : pchar);
  279. begin
  280. AllowSlash(p1);
  281. AllowSlash(p2);
  282. if MoveFile(p1,p2)=0 then
  283. Begin
  284. errno:=GetLastError;
  285. Errno2InoutRes;
  286. end;
  287. end;
  288. function do_write(h,addr,len : longint) : longint;
  289. var
  290. size:longint;
  291. begin
  292. if writefile(h,pointer(addr),len,size,nil)=0 then
  293. Begin
  294. errno:=GetLastError;
  295. Errno2InoutRes;
  296. end;
  297. do_write:=size;
  298. end;
  299. function do_read(h,addr,len : longint) : longint;
  300. var
  301. result:longint;
  302. begin
  303. if readfile(h,pointer(addr),len,result,nil)=0 then
  304. Begin
  305. errno:=GetLastError;
  306. Errno2InoutRes;
  307. end;
  308. do_read:=result;
  309. end;
  310. function do_filepos(handle : longint) : longint;
  311. var
  312. l:longint;
  313. begin
  314. l:=SetFilePointer(handle,0,nil,FILE_CURRENT);
  315. if l=-1 then
  316. begin
  317. l:=0;
  318. errno:=GetLastError;
  319. Errno2InoutRes;
  320. end;
  321. do_filepos:=l;
  322. end;
  323. procedure do_seek(handle,pos : longint);
  324. begin
  325. if SetFilePointer(handle,pos,nil,FILE_BEGIN)=-1 then
  326. Begin
  327. errno:=GetLastError;
  328. Errno2InoutRes;
  329. end;
  330. end;
  331. function do_seekend(handle:longint):longint;
  332. begin
  333. do_seekend:=SetFilePointer(handle,0,nil,FILE_END);
  334. if do_seekend=-1 then
  335. begin
  336. errno:=GetLastError;
  337. Errno2InoutRes;
  338. end;
  339. end;
  340. function do_filesize(handle : longint) : longint;
  341. var
  342. aktfilepos : longint;
  343. begin
  344. aktfilepos:=do_filepos(handle);
  345. do_filesize:=do_seekend(handle);
  346. do_seek(handle,aktfilepos);
  347. end;
  348. procedure do_truncate (handle,pos:longint);
  349. begin
  350. do_seek(handle,pos);
  351. if not(SetEndOfFile(handle)) then
  352. begin
  353. errno:=GetLastError;
  354. Errno2InoutRes;
  355. end;
  356. end;
  357. procedure do_open(var f;p : pchar;flags:longint);
  358. {
  359. filerec and textrec have both handle and mode as the first items so
  360. they could use the same routine for opening/creating.
  361. when (flags and $10) the file will be append
  362. when (flags and $100) the file will be truncate/rewritten
  363. when (flags and $1000) there is no check for close (needed for textfiles)
  364. }
  365. var
  366. oflags,cd : longint;
  367. begin
  368. AllowSlash(p);
  369. { close first if opened }
  370. if ((flags and $1000)=0) then
  371. begin
  372. case filerec(f).mode of
  373. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  374. fmclosed : ;
  375. else
  376. begin
  377. {not assigned}
  378. inoutres:=102;
  379. exit;
  380. end;
  381. end;
  382. end;
  383. { reset file handle }
  384. filerec(f).handle:=UnusedHandle;
  385. { convert filemode to filerec modes }
  386. case (flags and 3) of
  387. 0 : begin
  388. filerec(f).mode:=fminput;
  389. oflags:=GENERIC_READ;
  390. end;
  391. 1 : begin
  392. filerec(f).mode:=fmoutput;
  393. oflags:=GENERIC_WRITE;
  394. end;
  395. 2 : begin
  396. filerec(f).mode:=fminout;
  397. oflags:=GENERIC_WRITE or GENERIC_READ;
  398. end;
  399. end;
  400. { standard is opening and existing file }
  401. cd:=OPEN_EXISTING;
  402. { create it ? }
  403. if (flags and $100)<>0 then
  404. cd:=CREATE_ALWAYS
  405. { or append ? }
  406. else
  407. if (flags and $10)<>0 then
  408. cd:=OPEN_ALWAYS;
  409. { empty name is special }
  410. if p[0]=#0 then
  411. begin
  412. case filerec(f).mode of
  413. fminput : filerec(f).handle:=StdInputHandle;
  414. fmappend,
  415. fmoutput : begin
  416. filerec(f).handle:=StdOutputHandle;
  417. filerec(f).mode:=fmoutput; {fool fmappend}
  418. end;
  419. end;
  420. exit;
  421. end;
  422. filerec(f).handle:=CreateFile(p,oflags,0,nil,cd,FILE_ATTRIBUTE_NORMAL,0);
  423. { append mode }
  424. if (flags and $10)<>0 then
  425. begin
  426. do_seekend(filerec(f).handle);
  427. filerec(f).mode:=fmoutput; {fool fmappend}
  428. end;
  429. { get errors }
  430. if (filerec(f).handle=0) or (filerec(f).handle=-1) then
  431. { handle -1 is returned sometimes !! (PM) }
  432. begin
  433. errno:=GetLastError;
  434. Errno2InoutRes;
  435. end;
  436. end;
  437. function do_isdevice(handle:longint):boolean;
  438. begin
  439. do_isdevice:=(getfiletype(handle)=2);
  440. end;
  441. {*****************************************************************************
  442. UnTyped File Handling
  443. *****************************************************************************}
  444. {$i file.inc}
  445. {*****************************************************************************
  446. Typed File Handling
  447. *****************************************************************************}
  448. {$i typefile.inc}
  449. {*****************************************************************************
  450. Text File Handling
  451. *****************************************************************************}
  452. {$DEFINE EOF_CTRLZ}
  453. {$i text.inc}
  454. {*****************************************************************************
  455. Directory Handling
  456. *****************************************************************************}
  457. function CreateDirectory(name : pointer;sec : pointer) : longint;
  458. external 'kernel32' name 'CreateDirectoryA';
  459. function RemoveDirectory(name:pointer):longint;
  460. external 'kernel32' name 'RemoveDirectoryA';
  461. function SetCurrentDirectory(name : pointer) : longint;
  462. external 'kernel32' name 'SetCurrentDirectoryA';
  463. function GetCurrentDirectory(bufsize : longint;name : pchar) : longint;
  464. external 'kernel32' name 'GetCurrentDirectoryA';
  465. type
  466. TDirFnType=function(name:pointer):word;
  467. procedure dirfn(afunc : TDirFnType;const s:string);
  468. var
  469. buffer : array[0..255] of char;
  470. begin
  471. move(s[1],buffer,length(s));
  472. buffer[length(s)]:=#0;
  473. AllowSlash(pchar(@buffer));
  474. if aFunc(@buffer)=0 then
  475. begin
  476. errno:=GetLastError;
  477. Errno2InoutRes;
  478. end;
  479. end;
  480. function CreateDirectoryTrunc(name:pointer):word;
  481. begin
  482. CreateDirectoryTrunc:=CreateDirectory(name,nil);
  483. end;
  484. procedure mkdir(const s:string);[IOCHECK];
  485. begin
  486. If InOutRes <> 0 then exit;
  487. dirfn(TDirFnType(@CreateDirectoryTrunc),s);
  488. end;
  489. procedure rmdir(const s:string);[IOCHECK];
  490. begin
  491. If InOutRes <> 0 then exit;
  492. dirfn(TDirFnType(@RemoveDirectory),s);
  493. end;
  494. procedure chdir(const s:string);[IOCHECK];
  495. begin
  496. If InOutRes <> 0 then exit;
  497. dirfn(TDirFnType(@SetCurrentDirectory),s);
  498. end;
  499. procedure getdir(drivenr:byte;var dir:string);
  500. const
  501. Drive:array[0..3]of char=(#0,':',#0,#0);
  502. var
  503. defaultdrive:boolean;
  504. DirBuf,SaveBuf:array[0..259] of Char;
  505. begin
  506. defaultdrive:=drivenr=0;
  507. if not defaultdrive then
  508. begin
  509. byte(Drive[0]):=Drivenr+64;
  510. GetCurrentDirectory(SizeOf(SaveBuf),SaveBuf);
  511. SetCurrentDirectory(@Drive);
  512. end;
  513. GetCurrentDirectory(SizeOf(DirBuf),DirBuf);
  514. if not defaultdrive then
  515. SetCurrentDirectory(@SaveBuf);
  516. dir:=strpas(DirBuf);
  517. end;
  518. {*****************************************************************************
  519. SystemUnit Initialization
  520. *****************************************************************************}
  521. { Startup }
  522. procedure GetStartupInfo(p : pointer);
  523. external 'kernel32' name 'GetStartupInfoA';
  524. function GetStdHandle(nStdHandle:DWORD):THANDLE;
  525. external 'kernel32' name 'GetStdHandle';
  526. { command line/enviroment functions }
  527. function GetCommandLine : pchar;
  528. external 'kernel32' name 'GetCommandLineA';
  529. { module functions }
  530. function GetModuleFileName(l1:longint;p:pointer;l2:longint):longint;
  531. external 'kernel32' name 'GetModuleFileNameA';
  532. function GetModuleHandle(p : pointer) : longint;
  533. external 'kernel32' name 'GetModuleHandleA';
  534. var
  535. ModuleName : array[0..255] of char;
  536. function GetCommandFile:pchar;
  537. begin
  538. GetModuleFileName(0,@ModuleName,255);
  539. GetCommandFile:=@ModuleName;
  540. end;
  541. procedure setup_arguments;
  542. var
  543. arglen,
  544. count : longint;
  545. argstart,
  546. cmdline : pchar;
  547. quote : set of char;
  548. argsbuf : array[0..127] of pchar;
  549. begin
  550. { create commandline, it starts with the executed filename which is argv[0] }
  551. cmdline:=GetCommandLine;
  552. count:=0;
  553. repeat
  554. { skip leading spaces }
  555. while cmdline^ in [' ',#9,#13] do
  556. inc(longint(cmdline));
  557. case cmdline^ of
  558. #0 : break;
  559. '"' : begin
  560. quote:=['"'];
  561. inc(longint(cmdline));
  562. end;
  563. '''' : begin
  564. quote:=[''''];
  565. inc(longint(cmdline));
  566. end;
  567. else
  568. quote:=[' ',#9,#13];
  569. end;
  570. { scan until the end of the argument }
  571. argstart:=cmdline;
  572. while (cmdline^<>#0) and not(cmdline^ in quote) do
  573. inc(longint(cmdline));
  574. { reserve some memory }
  575. arglen:=cmdline-argstart;
  576. getmem(argsbuf[count],arglen+1);
  577. move(argstart^,argsbuf[count]^,arglen);
  578. argsbuf[count][arglen]:=#0;
  579. { skip quote }
  580. if cmdline^ in quote then
  581. inc(longint(cmdline));
  582. inc(count);
  583. until false;
  584. { create argc }
  585. argc:=count;
  586. { create an nil entry }
  587. argsbuf[count]:=nil;
  588. inc(count);
  589. { create the argv }
  590. getmem(argv,count shl 2);
  591. move(argsbuf,argv^,count shl 2);
  592. end;
  593. {$ASMMODE DIRECT}
  594. procedure Entry;[public,alias: '_mainCRTStartup'];
  595. begin
  596. { call to the pascal main }
  597. asm
  598. call PASCALMAIN
  599. end;
  600. { that's all folks }
  601. ExitProcess(0);
  602. end;
  603. {$ifdef dummy}
  604. Function SetUpStack : longint;
  605. { This routine does the following : }
  606. { returns the value of the initial SP - __stklen }
  607. begin
  608. asm
  609. pushl %ebx
  610. pushl %eax
  611. movl __stklen,%ebx
  612. movl %esp,%eax
  613. subl %ebx,%eax
  614. movl %eax,__RESULT
  615. popl %eax
  616. popl %ebx
  617. end;
  618. end;
  619. {$endif}
  620. {$ASMMODE ATT}
  621. begin
  622. { get some helpful informations }
  623. GetStartupInfo(@startupinfo);
  624. { some misc Win32 stuff }
  625. hprevinst:=0;
  626. hinstance:=getmodulehandle(GetCommandFile);
  627. cmdshow:=startupinfo.wshowwindow;
  628. { to test stack depth }
  629. loweststack:=maxlongint;
  630. { real test stack depth }
  631. { stacklimit := setupstack; }
  632. { Setup heap }
  633. {$ifndef WinHeap}
  634. InitHeap;
  635. {$endif WinHeap}
  636. { Setup stdin, stdout and stderr }
  637. StdInputHandle:=longint(GetStdHandle(STD_INPUT_HANDLE));
  638. StdOutputHandle:=longint(GetStdHandle(STD_OUTPUT_HANDLE));
  639. StdErrorHandle:=longint(GetStdHandle(STD_ERROR_HANDLE));
  640. OpenStdIO(Input,fmInput,StdInputHandle);
  641. OpenStdIO(Output,fmOutput,StdOutputHandle);
  642. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  643. { Arguments }
  644. setup_arguments;
  645. { Reset IO Error }
  646. InOutRes:=0;
  647. { Reset internal error variable }
  648. errno := 0;
  649. end.
  650. {
  651. $Log$
  652. Revision 1.19 1998-09-02 09:03:46 pierre
  653. * do_open sometimes returns -1 as handle on fail
  654. was not checked correctly
  655. Revision 1.16 1998/08/24 14:45:22 pierre
  656. * sbrk was wrong
  657. heap growing now works for win32
  658. Revision 1.15 1998/08/21 10:10:16 peter
  659. * winheap turned off by default
  660. Revision 1.14 1998/07/30 13:27:19 michael
  661. + Added support for errorproc. Changed runerror to HandleError
  662. Revision 1.13 1998/07/13 21:19:15 florian
  663. * some problems with ansi string support fixed
  664. Revision 1.12 1998/07/07 12:37:28 carl
  665. * correct mapping of error codes for TP compatibility
  666. + implemented stack checking in ifdef dummy
  667. Revision 1.11 1998/07/02 12:33:18 carl
  668. * IOCheck/InOutRes check for mkdir,rmdir and chdir like in TP
  669. Revision 1.10 1998/07/01 15:30:02 peter
  670. * better readln/writeln
  671. Revision 1.9 1998/06/10 10:39:17 peter
  672. * working w32 rtl
  673. Revision 1.8 1998/06/08 23:07:47 peter
  674. * dos interface is now 100% compatible
  675. * fixed call PASCALMAIN which must be direct asm
  676. Revision 1.7 1998/05/06 12:36:51 michael
  677. + Removed log from before restored version.
  678. Revision 1.6 1998/04/27 18:29:09 florian
  679. + do_open implemented, the file-I/O should be now complete
  680. Revision 1.5 1998/04/27 13:58:21 florian
  681. + paramstr/paramcount implemented
  682. Revision 1.4 1998/04/26 22:37:22 florian
  683. * some small extensions
  684. Revision 1.3 1998/04/26 21:49:57 florian
  685. + more stuff added (??dir procedures etc.)
  686. }