syswin32.pp 22 KB

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