sysinitpas.pp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2006 by Florian Klaempfl and Pavel Ozerski
  4. member of the Free Pascal development team.
  5. Win32 pascal only startup code
  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 sysinitpas;
  13. interface
  14. implementation
  15. var
  16. SysInstance : Longint;external name '_FPC_SysInstance';
  17. EntryInformation : TEntryInformation;
  18. InitFinalTable : record end; external name 'INITFINAL';
  19. ThreadvarTablesTable : record end; external name 'FPC_THREADVARTABLES';
  20. valgrind_used : boolean;external name '__fpc_valgrind';
  21. procedure asm_exit;stdcall;public name 'asm_exit';
  22. begin
  23. end;
  24. procedure EXE_Entry(const info : TEntryInformation); external name '_FPC_EXE_Entry';
  25. function DLL_entry(const info : TEntryInformation) : longbool; external name '_FPC_DLL_Entry';
  26. procedure PascalMain;stdcall;external name 'PASCALMAIN';
  27. procedure SetupEntryInformation;
  28. begin
  29. EntryInformation.InitFinalTable:=@InitFinalTable;
  30. EntryInformation.ThreadvarTablesTable:=@ThreadvarTablesTable;
  31. EntryInformation.asm_exit:=@asm_exit;
  32. EntryInformation.PascalMain:=@PascalMain;
  33. EntryInformation.valgrind_used:=valgrind_used;
  34. end;
  35. const
  36. STD_INPUT_HANDLE = dword(-10);
  37. function GetStdHandle(nStdHandle:DWORD) : THandle; stdcall; external 'kernel32' name 'GetStdHandle';
  38. function GetConsoleMode(hConsoleHandle: THandle; var lpMode: DWORD): Boolean; stdcall; external 'kernel32' name 'GetConsoleMode';
  39. procedure _FPC_mainCRTStartup;stdcall;public name '_mainCRTStartup';
  40. begin
  41. IsConsole:=true;
  42. { do it like it is necessary for the startup code linking against cygwin }
  43. GetConsoleMode(GetStdHandle((Std_Input_Handle)),StartupConsoleMode);
  44. SetupEntryInformation;
  45. Exe_entry(EntryInformation);
  46. end;
  47. procedure _FPC_WinMainCRTStartup;stdcall;public name '_WinMainCRTStartup';
  48. begin
  49. IsConsole:=false;
  50. SetupEntryInformation;
  51. Exe_entry(EntryInformation);
  52. end;
  53. procedure _FPC_DLLMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLMainCRTStartup';
  54. begin
  55. IsConsole:=true;
  56. sysinstance:=_hinstance;
  57. dllreason:=_dllreason;
  58. dllparam:=_dllparam;
  59. SetupEntryInformation;
  60. DLL_Entry(EntryInformation);
  61. end;
  62. procedure _FPC_DLLWinMainCRTStartup(_hinstance,_dllreason,_dllparam:longint);stdcall;public name '_DLLWinMainCRTStartup';
  63. begin
  64. IsConsole:=false;
  65. sysinstance:=_hinstance;
  66. dllreason:=_dllreason;
  67. dllparam:=_dllparam;
  68. SetupEntryInformation;
  69. DLL_Entry(EntryInformation);
  70. end;
  71. end.