SDL_main_impl.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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__)
  29. /* these defines/typedefs are needed for the WinMain() definition */
  30. #ifndef WINAPI
  31. #define WINAPI __stdcall
  32. #endif
  33. typedef struct HINSTANCE__ * HINSTANCE;
  34. typedef char* LPSTR;
  35. #ifdef main
  36. # undef main
  37. #endif /* main */
  38. #include <SDL3/begin_code.h>
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. #if defined(_MSC_VER)
  43. /* The VC++ compiler needs main/wmain defined */
  44. # define console_ansi_main main
  45. # if defined(UNICODE) && UNICODE
  46. # define console_wmain wmain
  47. # endif
  48. #endif
  49. #if defined( UNICODE ) && UNICODE
  50. /* This is where execution begins [console apps, unicode] */
  51. int
  52. console_wmain(int argc, wchar_t *wargv[], wchar_t *wenvp)
  53. {
  54. return SDL_Win32RunApp(SDL_main, NULL);
  55. }
  56. #else /* ANSI */
  57. /* This is where execution begins [console apps, ansi] */
  58. int
  59. console_ansi_main(int argc, char *argv[])
  60. {
  61. return SDL_Win32RunApp(SDL_main, NULL);
  62. }
  63. #endif /* UNICODE/ANSI */
  64. /* This is where execution begins [windowed apps] */
  65. int WINAPI
  66. WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
  67. {
  68. return SDL_Win32RunApp(SDL_main, NULL);
  69. }
  70. #ifdef __cplusplus
  71. } /* extern "C" */
  72. #endif
  73. #include <SDL3/close_code.h>
  74. /* rename users main() function to SDL_main() so it can be called from the wrapper above */
  75. #define main SDL_main
  76. #elif 1 /* end of __WIN32__ impl - TODO: other platforms */
  77. #endif /* __WIN32__ etc */
  78. #endif /* SDL_MAIN_HANDLED */
  79. #endif /* SDL_main_windows_h_ */
  80. /* vi: set ts=4 sw=4 expandtab: */