wincrt1.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //+---------------------------------------------------------------------------
  2. // _UNICODE for tchar.h, UNICODE for API
  3. #include <tchar.h>
  4. #include <windows.h>
  5. #include <stdlib.h>
  6. #define __UNKNOWN_APP 0
  7. #define __CONSOLE_APP 1
  8. #define __GUI_APP 2
  9. void __set_app_type(int);
  10. void _controlfp(unsigned a, unsigned b);
  11. #ifdef _UNICODE
  12. #define __tgetmainargs __wgetmainargs
  13. #define _twinstart _wwinstart
  14. #define _runtwinmain _runwwinmain
  15. int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);
  16. #else
  17. #define __tgetmainargs __getmainargs
  18. #define _twinstart _winstart
  19. #define _runtwinmain _runwinmain
  20. #endif
  21. typedef struct { int newmode; } _startupinfo;
  22. int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
  23. static int go_winmain(TCHAR *arg1)
  24. {
  25. STARTUPINFO si;
  26. _TCHAR *szCmd, *p;
  27. int fShow;
  28. GetStartupInfo(&si);
  29. if (si.dwFlags & STARTF_USESHOWWINDOW)
  30. fShow = si.wShowWindow;
  31. else
  32. fShow = SW_SHOWDEFAULT;
  33. szCmd = NULL, p = GetCommandLine();
  34. if (arg1)
  35. szCmd = _tcsstr(p, arg1);
  36. if (NULL == szCmd)
  37. szCmd = _tcsdup(__T(""));
  38. else if (szCmd > p && szCmd[-1] == __T('"'))
  39. --szCmd;
  40. #if defined __i386__ || defined __x86_64__
  41. _controlfp(0x10000, 0x30000);
  42. #endif
  43. return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow);
  44. }
  45. int _twinstart(void)
  46. {
  47. __TRY__
  48. _startupinfo start_info_con = {0};
  49. __set_app_type(__GUI_APP);
  50. __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con);
  51. exit(go_winmain(__argc > 1 ? __targv[1] : NULL));
  52. }
  53. int _runtwinmain(int argc, /* as tcc passed in */ char **argv)
  54. {
  55. #ifdef UNICODE
  56. _startupinfo start_info = {0};
  57. __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info);
  58. /* may be wrong when tcc has received wildcards (*.c) */
  59. if (argc < __argc)
  60. __targv += __argc - argc, __argc = argc;
  61. #else
  62. __argc = argc, __targv = argv;
  63. #endif
  64. return go_winmain(__argc > 1 ? __targv[1] : NULL);
  65. }