SDL_main_impl.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef SDL_main_windows_h_
  19. #define SDL_main_windows_h_
  20. #if !defined(SDL_main_h_)
  21. #error "This header should not be included directly, but only via SDL_main.h!"
  22. #endif
  23. /* if someone wants to include SDL_main.h but doesn't want the main handing magic,
  24. (maybe to call SDL_RegisterApp()) they can #define SDL_MAIN_HANDLED first
  25. _SDL_MAIN_NOIMPL is for SDL-internal usage (only affects implementation,
  26. not definition of SDL_MAIN_AVAILABLE etc in SDL_main.h) */
  27. #if !defined(SDL_MAIN_HANDLED) && !defined(_SDL_MAIN_NOIMPL)
  28. #if defined(__WIN32__) || defined(__GDK__)
  29. /* these defines/typedefs are needed for the WinMain() definition */
  30. #ifndef WINAPI
  31. #define WINAPI __stdcall
  32. #endif
  33. #ifdef main
  34. # undef main
  35. #endif /* main */
  36. #include <SDL3/begin_code.h>
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. typedef struct HINSTANCE__ * HINSTANCE;
  41. typedef char* LPSTR;
  42. #ifndef __GDK__ /* this is only needed for Win32 */
  43. #if defined(_MSC_VER)
  44. /* The VC++ compiler needs main/wmain defined */
  45. # define console_ansi_main main
  46. # if defined(UNICODE) && UNICODE
  47. # define console_wmain wmain
  48. # endif
  49. #endif
  50. #if defined( UNICODE ) && UNICODE
  51. /* This is where execution begins [console apps, unicode] */
  52. int
  53. console_wmain(int argc, wchar_t *wargv[], wchar_t *wenvp)
  54. {
  55. return SDL_Win32RunApp(SDL_main, NULL);
  56. }
  57. #else /* ANSI */
  58. /* This is where execution begins [console apps, ansi] */
  59. int
  60. console_ansi_main(int argc, char *argv[])
  61. {
  62. return SDL_Win32RunApp(SDL_main, NULL);
  63. }
  64. #endif /* UNICODE/ANSI */
  65. #endif /* not __GDK__ */
  66. /* This is where execution begins [windowed apps and GDK] */
  67. int WINAPI
  68. WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
  69. {
  70. #ifdef __GDK__
  71. return SDL_GDKRunApp(SDL_main, NULL);
  72. #else
  73. return SDL_Win32RunApp(SDL_main, NULL);
  74. #endif
  75. }
  76. #ifdef __cplusplus
  77. } /* extern "C" */
  78. #endif
  79. #include <SDL3/close_code.h>
  80. /* rename users main() function to SDL_main() so it can be called from the wrapper above */
  81. #define main SDL_main
  82. /* end of __WIN32__ and __GDK__ impls */
  83. #elif defined(__IOS__) || defined(__TVOS__)
  84. #ifdef main
  85. # undef main
  86. #endif /* main */
  87. #include <SDL3/begin_code.h>
  88. #ifdef __cplusplus
  89. extern "C" {
  90. #endif
  91. int main(int argc, char *argv[])
  92. {
  93. return SDL_UIKitRunApp(argc, argv, SDL_main);
  94. }
  95. #ifdef __cplusplus
  96. } /* extern "C" */
  97. #endif
  98. #include <SDL3/close_code.h>
  99. /* rename users main() function to SDL_main() so it can be called from the wrapper above */
  100. #define main SDL_main
  101. /* end of __IOS__ and __TVOS__ impls */
  102. /* TODO: remaining platforms */
  103. #endif /* __WIN32__ etc */
  104. #endif /* SDL_MAIN_HANDLED */
  105. #endif /* SDL_main_windows_h_ */
  106. /* vi: set ts=4 sw=4 expandtab: */