SDL_main.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
  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_h_
  19. #define SDL_main_h_
  20. #include "SDL_stdinc.h"
  21. /**
  22. * \file SDL_main.h
  23. *
  24. * Redefine main() on some platforms so that it is called by SDL.
  25. */
  26. #ifndef SDL_MAIN_HANDLED
  27. #if defined(__WIN32__)
  28. /* On Windows SDL provides WinMain(), which parses the command line and passes
  29. the arguments to your main function.
  30. If you provide your own WinMain(), you may define SDL_MAIN_HANDLED
  31. */
  32. #define SDL_MAIN_AVAILABLE
  33. #elif defined(__GDK__)
  34. /* On GDK, SDL provides a main function that initializes the game runtime.
  35. Please note that #include'ing SDL_main.h is not enough to get a main()
  36. function working. You must either link against SDL3main or, if not possible,
  37. call the SDL_GDKRunApp function from your entry point.
  38. */
  39. #define SDL_MAIN_NEEDED
  40. #elif defined(__IPHONEOS__)
  41. /* On iOS SDL provides a main function that creates an application delegate
  42. and starts the iOS application run loop.
  43. If you link with SDL dynamically on iOS, the main function can't be in a
  44. shared library, so you need to link with libSDLmain.a, which includes a
  45. stub main function that calls into the shared library to start execution.
  46. See src/video/uikit/SDL_uikitappdelegate.m for more details.
  47. */
  48. #define SDL_MAIN_NEEDED
  49. #elif defined(__ANDROID__)
  50. /* On Android SDL provides a Java class in SDLActivity.java that is the
  51. main activity entry point.
  52. See docs/README-android.md for more details on extending that class.
  53. */
  54. #define SDL_MAIN_NEEDED
  55. /* We need to export SDL_main so it can be launched from Java */
  56. #define SDLMAIN_DECLSPEC DECLSPEC
  57. #elif defined(__PSP__)
  58. /* On PSP SDL provides a main function that sets the module info,
  59. activates the GPU and starts the thread required to be able to exit
  60. the software.
  61. If you provide this yourself, you may define SDL_MAIN_HANDLED
  62. */
  63. #define SDL_MAIN_AVAILABLE
  64. #elif defined(__PS2__)
  65. #define SDL_MAIN_AVAILABLE
  66. #define SDL_PS2_SKIP_IOP_RESET() \
  67. void reset_IOP(); \
  68. void reset_IOP() {}
  69. #elif defined(__3DS__)
  70. /*
  71. On N3DS, SDL provides a main function that sets up the screens
  72. and storage.
  73. If you provide this yourself, you may define SDL_MAIN_HANDLED
  74. */
  75. #define SDL_MAIN_AVAILABLE
  76. #endif
  77. #endif /* SDL_MAIN_HANDLED */
  78. #ifndef SDLMAIN_DECLSPEC
  79. #define SDLMAIN_DECLSPEC
  80. #endif
  81. /**
  82. * \file SDL_main.h
  83. *
  84. * The application's main() function must be called with C linkage,
  85. * and should be declared like this:
  86. * \code
  87. * #ifdef __cplusplus
  88. * extern "C"
  89. * #endif
  90. * int main(int argc, char *argv[])
  91. * {
  92. * }
  93. * \endcode
  94. */
  95. #if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE)
  96. #define main SDL_main
  97. #endif
  98. #include "begin_code.h"
  99. #ifdef __cplusplus
  100. extern "C" {
  101. #endif
  102. /**
  103. * The prototype for the application's main() function
  104. */
  105. typedef int (*SDL_main_func)(int argc, char *argv[]);
  106. extern SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]);
  107. /**
  108. * Circumvent failure of SDL_Init() when not using SDL_main() as an entry
  109. * point.
  110. *
  111. * This function is defined in SDL_main.h, along with the preprocessor rule to
  112. * redefine main() as SDL_main(). Thus to ensure that your main() function
  113. * will not be changed it is necessary to define SDL_MAIN_HANDLED before
  114. * including SDL.h.
  115. *
  116. * \since This function is available since SDL 3.0.0.
  117. *
  118. * \sa SDL_Init
  119. */
  120. extern DECLSPEC void SDLCALL SDL_SetMainReady(void);
  121. #if defined(__WIN32__) || defined(__GDK__)
  122. /**
  123. * Register a win32 window class for SDL's use.
  124. *
  125. * This can be called to set the application window class at startup. It is
  126. * safe to call this multiple times, as long as every call is eventually
  127. * paired with a call to SDL_UnregisterApp, but a second registration attempt
  128. * while a previous registration is still active will be ignored, other than
  129. * to increment a counter.
  130. *
  131. * Most applications do not need to, and should not, call this directly; SDL
  132. * will call it when initializing the video subsystem.
  133. *
  134. * \param name the window class name, in UTF-8 encoding. If NULL, SDL
  135. * currently uses "SDL_app" but this isn't guaranteed.
  136. * \param style the value to use in WNDCLASSEX::style. If `name` is NULL, SDL
  137. * currently uses `(CS_BYTEALIGNCLIENT | CS_OWNDC)` regardless of
  138. * what is specified here.
  139. * \param hInst the HINSTANCE to use in WNDCLASSEX::hInstance. If zero, SDL
  140. * will use `GetModuleHandle(NULL)` instead.
  141. * \returns 0 on success, -1 on error. SDL_GetError() may have details.
  142. *
  143. * \since This function is available since SDL 3.0.0.
  144. */
  145. extern DECLSPEC int SDLCALL SDL_RegisterApp(const char *name, Uint32 style, void *hInst);
  146. /**
  147. * Deregister the win32 window class from an SDL_RegisterApp call.
  148. *
  149. * This can be called to undo the effects of SDL_RegisterApp.
  150. *
  151. * Most applications do not need to, and should not, call this directly; SDL
  152. * will call it when deinitializing the video subsystem.
  153. *
  154. * It is safe to call this multiple times, as long as every call is eventually
  155. * paired with a prior call to SDL_RegisterApp. The window class will only be
  156. * deregistered when the registration counter in SDL_RegisterApp decrements to
  157. * zero through calls to this function.
  158. *
  159. * \since This function is available since SDL 3.0.0.
  160. */
  161. extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
  162. #endif /* defined(__WIN32__) || defined(__GDK__) */
  163. #if defined(__IPHONEOS__)
  164. /**
  165. * Initializes and launches an SDL application.
  166. *
  167. * \param argc The argc parameter from the application's main() function
  168. * \param argv The argv parameter from the application's main() function
  169. * \param mainFunction The SDL app's C-style main(), an SDL_main_func
  170. * \return the return value from mainFunction
  171. *
  172. * \since This function is available since SDL 3.0.0.
  173. */
  174. extern DECLSPEC int SDLCALL SDL_UIKitRunApp(int argc, char *argv[], SDL_main_func mainFunction);
  175. #endif /* __IPHONEOS__ */
  176. #ifdef __GDK__
  177. /**
  178. * Initialize and launch an SDL GDK application.
  179. *
  180. * \param mainFunction the SDL app's C-style main(), an SDL_main_func
  181. * \param reserved reserved for future use; should be NULL
  182. * \returns 0 on success or -1 on failure; call SDL_GetError() to retrieve
  183. * more information on the failure.
  184. *
  185. * \since This function is available since SDL 3.0.0.
  186. */
  187. extern DECLSPEC int SDLCALL SDL_GDKRunApp(SDL_main_func mainFunction, void *reserved);
  188. #endif /* __GDK__ */
  189. #ifdef __cplusplus
  190. }
  191. #endif
  192. #include "close_code.h"
  193. #endif /* SDL_main_h_ */
  194. /* vi: set ts=4 sw=4 expandtab: */