SDL_main.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 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. /**
  19. * # CategoryMain
  20. *
  21. * Redefine main() if necessary so that it is called by SDL.
  22. *
  23. * In order to make this consistent on all platforms, the application's main()
  24. * should look like this:
  25. *
  26. * ```c
  27. * int main(int argc, char *argv[])
  28. * {
  29. * }
  30. * ```
  31. *
  32. * SDL will take care of platform specific details on how it gets called.
  33. *
  34. * This is also where an app can be configured to use the main callbacks, via
  35. * the SDL_MAIN_USE_CALLBACKS macro.
  36. *
  37. * This is a "single-header library," which is to say that including this
  38. * header inserts code into your program, and you should only include it once
  39. * in most cases. SDL.h does not include this header automatically.
  40. *
  41. * For more information, see:
  42. *
  43. * https://wiki.libsdl.org/SDL3/README/main-functions
  44. */
  45. #ifndef SDL_main_h_
  46. #define SDL_main_h_
  47. #include <SDL3/SDL_platform_defines.h>
  48. #include <SDL3/SDL_stdinc.h>
  49. #include <SDL3/SDL_error.h>
  50. #include <SDL3/SDL_events.h>
  51. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  52. /**
  53. * Inform SDL that the app is providing an entry point instead of SDL.
  54. *
  55. * SDL does not define this macro, but will check if it is defined when
  56. * including `SDL_main.h`. If defined, SDL will expect the app to provide the
  57. * proper entry point for the platform, and all the other magic details
  58. * needed, like manually calling SDL_SetMainReady.
  59. *
  60. * Please see [README/main-functions](README/main-functions), (or
  61. * docs/README-main-functions.md in the source tree) for a more detailed
  62. * explanation.
  63. *
  64. * \since This macro is used by the headers since SDL 3.2.0.
  65. */
  66. #define SDL_MAIN_HANDLED 1
  67. /**
  68. * Inform SDL to use the main callbacks instead of main.
  69. *
  70. * SDL does not define this macro, but will check if it is defined when
  71. * including `SDL_main.h`. If defined, SDL will expect the app to provide
  72. * several functions: SDL_AppInit, SDL_AppEvent, SDL_AppIterate, and
  73. * SDL_AppQuit. The app should not provide a `main` function in this case, and
  74. * doing so will likely cause the build to fail.
  75. *
  76. * Please see [README/main-functions](README/main-functions), (or
  77. * docs/README-main-functions.md in the source tree) for a more detailed
  78. * explanation.
  79. *
  80. * \since This macro is used by the headers since SDL 3.2.0.
  81. *
  82. * \sa SDL_AppInit
  83. * \sa SDL_AppEvent
  84. * \sa SDL_AppIterate
  85. * \sa SDL_AppQuit
  86. */
  87. #define SDL_MAIN_USE_CALLBACKS 1
  88. /**
  89. * Defined if the target platform offers a special mainline through SDL.
  90. *
  91. * This won't be defined otherwise. If defined, SDL's headers will redefine
  92. * `main` to `SDL_main`.
  93. *
  94. * This macro is defined by `SDL_main.h`, which is not automatically included
  95. * by `SDL.h`.
  96. *
  97. * Even if available, an app can define SDL_MAIN_HANDLED and provide their
  98. * own, if they know what they're doing.
  99. *
  100. * This macro is used internally by SDL, and apps probably shouldn't rely on it.
  101. *
  102. * \since This macro is available since SDL 3.2.0.
  103. */
  104. #define SDL_MAIN_AVAILABLE
  105. /**
  106. * Defined if the target platform _requires_ a special mainline through SDL.
  107. *
  108. * This won't be defined otherwise. If defined, SDL's headers will redefine
  109. * `main` to `SDL_main`.
  110. *
  111. * This macro is defined by `SDL_main.h`, which is not automatically included
  112. * by `SDL.h`.
  113. *
  114. * Even if required, an app can define SDL_MAIN_HANDLED and provide their
  115. * own, if they know what they're doing.
  116. *
  117. * This macro is used internally by SDL, and apps probably shouldn't rely on it.
  118. *
  119. * \since This macro is available since SDL 3.2.0.
  120. */
  121. #define SDL_MAIN_NEEDED
  122. #endif
  123. #if defined(__has_include)
  124. #if __has_include("SDL_main_private.h") && __has_include("SDL_main_impl_private.h")
  125. #define SDL_PLATFORM_PRIVATE_MAIN
  126. #endif
  127. #endif
  128. #ifndef SDL_MAIN_HANDLED
  129. #if defined(SDL_PLATFORM_PRIVATE_MAIN)
  130. /* Private platforms may have their own ideas about entry points. */
  131. #include "SDL_main_private.h"
  132. #elif defined(SDL_PLATFORM_WIN32)
  133. /* On Windows SDL provides WinMain(), which parses the command line and passes
  134. the arguments to your main function.
  135. If you provide your own WinMain(), you may define SDL_MAIN_HANDLED
  136. */
  137. #define SDL_MAIN_AVAILABLE
  138. #elif defined(SDL_PLATFORM_GDK)
  139. /* On GDK, SDL provides a main function that initializes the game runtime.
  140. If you prefer to write your own WinMain-function instead of having SDL
  141. provide one that calls your main() function,
  142. #define SDL_MAIN_HANDLED before #include'ing SDL_main.h
  143. and call the SDL_RunApp function from your entry point.
  144. */
  145. #define SDL_MAIN_NEEDED
  146. #elif defined(SDL_PLATFORM_IOS)
  147. /* On iOS SDL provides a main function that creates an application delegate
  148. and starts the iOS application run loop.
  149. To use it, just #include SDL_main.h in the source file that contains your
  150. main() function.
  151. See src/video/uikit/SDL_uikitappdelegate.m for more details.
  152. */
  153. #define SDL_MAIN_NEEDED
  154. #elif defined(SDL_PLATFORM_ANDROID)
  155. /* On Android SDL provides a Java class in SDLActivity.java that is the
  156. main activity entry point.
  157. See docs/README-android.md for more details on extending that class.
  158. */
  159. #define SDL_MAIN_NEEDED
  160. /* As this is launched from Java, the real entry point (main() function)
  161. is outside of the the binary built from this code.
  162. This define makes sure that, unlike on other platforms, SDL_main.h
  163. and SDL_main_impl.h export an `SDL_main()` function (to be called
  164. from Java), but don't implement a native `int main(int argc, char* argv[])`
  165. or similar.
  166. */
  167. #define SDL_MAIN_EXPORTED
  168. #elif defined(SDL_PLATFORM_EMSCRIPTEN)
  169. /* On Emscripten, SDL provides a main function that converts URL
  170. parameters that start with "SDL_" to environment variables, so
  171. they can be used as SDL hints, etc.
  172. This is 100% optional, so if you don't want this to happen, you may
  173. define SDL_MAIN_HANDLED
  174. */
  175. #define SDL_MAIN_AVAILABLE
  176. #elif defined(SDL_PLATFORM_PSP)
  177. /* On PSP SDL provides a main function that sets the module info,
  178. activates the GPU and starts the thread required to be able to exit
  179. the software.
  180. If you provide this yourself, you may define SDL_MAIN_HANDLED
  181. */
  182. #define SDL_MAIN_AVAILABLE
  183. #elif defined(SDL_PLATFORM_PS2)
  184. #define SDL_MAIN_AVAILABLE
  185. #define SDL_PS2_SKIP_IOP_RESET() \
  186. void reset_IOP(); \
  187. void reset_IOP() {}
  188. #elif defined(SDL_PLATFORM_3DS)
  189. /*
  190. On N3DS, SDL provides a main function that sets up the screens
  191. and storage.
  192. If you provide this yourself, you may define SDL_MAIN_HANDLED
  193. */
  194. #define SDL_MAIN_AVAILABLE
  195. #endif
  196. #endif /* SDL_MAIN_HANDLED */
  197. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  198. /**
  199. * A macro to tag a main entry point function as exported.
  200. *
  201. * Most platforms don't need this, and the macro will be defined to nothing.
  202. * Some, like Android, keep the entry points in a shared library and need to
  203. * explicitly export the symbols.
  204. *
  205. * External code rarely needs this, and if it needs something, it's almost
  206. * always SDL_DECLSPEC instead.
  207. *
  208. * \since This macro is available since SDL 3.2.0.
  209. *
  210. * \sa SDL_DECLSPEC
  211. */
  212. #define SDLMAIN_DECLSPEC
  213. #elif defined(SDL_MAIN_EXPORTED)
  214. /* We need to export SDL_main so it can be launched from external code,
  215. like SDLActivity.java on Android */
  216. #define SDLMAIN_DECLSPEC SDL_DECLSPEC
  217. #else
  218. /* usually this is empty */
  219. #define SDLMAIN_DECLSPEC
  220. #endif /* SDL_MAIN_EXPORTED */
  221. #if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE) || defined(SDL_MAIN_USE_CALLBACKS)
  222. #define main SDL_main
  223. #endif
  224. #include <SDL3/SDL_init.h>
  225. #include <SDL3/SDL_begin_code.h>
  226. #ifdef __cplusplus
  227. extern "C" {
  228. #endif
  229. /*
  230. * You can (optionally!) define SDL_MAIN_USE_CALLBACKS before including
  231. * SDL_main.h, and then your application will _not_ have a standard
  232. * "main" entry point. Instead, it will operate as a collection of
  233. * functions that are called as necessary by the system. On some
  234. * platforms, this is just a layer where SDL drives your program
  235. * instead of your program driving SDL, on other platforms this might
  236. * hook into the OS to manage the lifecycle. Programs on most platforms
  237. * can use whichever approach they prefer, but the decision boils down
  238. * to:
  239. *
  240. * - Using a standard "main" function: this works like it always has for
  241. * the past 50+ years in C programming, and your app is in control.
  242. * - Using the callback functions: this might clean up some code,
  243. * avoid some #ifdef blocks in your program for some platforms, be more
  244. * resource-friendly to the system, and possibly be the primary way to
  245. * access some future platforms (but none require this at the moment).
  246. *
  247. * This is up to the app; both approaches are considered valid and supported
  248. * ways to write SDL apps.
  249. *
  250. * If using the callbacks, don't define a "main" function. Instead, implement
  251. * the functions listed below in your program.
  252. */
  253. #ifdef SDL_MAIN_USE_CALLBACKS
  254. /**
  255. * App-implemented initial entry point for SDL_MAIN_USE_CALLBACKS apps.
  256. *
  257. * Apps implement this function when using SDL_MAIN_USE_CALLBACKS. If using a
  258. * standard "main" function, you should not supply this.
  259. *
  260. * This function is called by SDL once, at startup. The function should
  261. * initialize whatever is necessary, possibly create windows and open audio
  262. * devices, etc. The `argc` and `argv` parameters work like they would with a
  263. * standard "main" function.
  264. *
  265. * This function should not go into an infinite mainloop; it should do any
  266. * one-time setup it requires and then return.
  267. *
  268. * The app may optionally assign a pointer to `*appstate`. This pointer will
  269. * be provided on every future call to the other entry points, to allow
  270. * application state to be preserved between functions without the app needing
  271. * to use a global variable. If this isn't set, the pointer will be NULL in
  272. * future entry points.
  273. *
  274. * If this function returns SDL_APP_CONTINUE, the app will proceed to normal
  275. * operation, and will begin receiving repeated calls to SDL_AppIterate and
  276. * SDL_AppEvent for the life of the program. If this function returns
  277. * SDL_APP_FAILURE, SDL will call SDL_AppQuit and terminate the process with
  278. * an exit code that reports an error to the platform. If it returns
  279. * SDL_APP_SUCCESS, SDL calls SDL_AppQuit and terminates with an exit code
  280. * that reports success to the platform.
  281. *
  282. * This function is called by SDL on the main thread.
  283. *
  284. * \param appstate a place where the app can optionally store a pointer for
  285. * future use.
  286. * \param argc the standard ANSI C main's argc; number of elements in `argv`.
  287. * \param argv the standard ANSI C main's argv; array of command line
  288. * arguments.
  289. * \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to
  290. * terminate with success, SDL_APP_CONTINUE to continue.
  291. *
  292. * \since This function is available since SDL 3.2.0.
  293. *
  294. * \sa SDL_AppIterate
  295. * \sa SDL_AppEvent
  296. * \sa SDL_AppQuit
  297. */
  298. extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppInit(void **appstate, int argc, char *argv[]);
  299. /**
  300. * App-implemented iteration entry point for SDL_MAIN_USE_CALLBACKS apps.
  301. *
  302. * Apps implement this function when using SDL_MAIN_USE_CALLBACKS. If using a
  303. * standard "main" function, you should not supply this.
  304. *
  305. * This function is called repeatedly by SDL after SDL_AppInit returns 0. The
  306. * function should operate as a single iteration the program's primary loop;
  307. * it should update whatever state it needs and draw a new frame of video,
  308. * usually.
  309. *
  310. * On some platforms, this function will be called at the refresh rate of the
  311. * display (which might change during the life of your app!). There are no
  312. * promises made about what frequency this function might run at. You should
  313. * use SDL's timer functions if you need to see how much time has passed since
  314. * the last iteration.
  315. *
  316. * There is no need to process the SDL event queue during this function; SDL
  317. * will send events as they arrive in SDL_AppEvent, and in most cases the
  318. * event queue will be empty when this function runs anyhow.
  319. *
  320. * This function should not go into an infinite mainloop; it should do one
  321. * iteration of whatever the program does and return.
  322. *
  323. * The `appstate` parameter is an optional pointer provided by the app during
  324. * SDL_AppInit(). If the app never provided a pointer, this will be NULL.
  325. *
  326. * If this function returns SDL_APP_CONTINUE, the app will continue normal
  327. * operation, receiving repeated calls to SDL_AppIterate and SDL_AppEvent for
  328. * the life of the program. If this function returns SDL_APP_FAILURE, SDL will
  329. * call SDL_AppQuit and terminate the process with an exit code that reports
  330. * an error to the platform. If it returns SDL_APP_SUCCESS, SDL calls
  331. * SDL_AppQuit and terminates with an exit code that reports success to the
  332. * platform.
  333. *
  334. * This function is called by SDL on the main thread.
  335. *
  336. * \param appstate an optional pointer, provided by the app in SDL_AppInit.
  337. * \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to
  338. * terminate with success, SDL_APP_CONTINUE to continue.
  339. *
  340. * \threadsafety This function may get called concurrently with SDL_AppEvent()
  341. * for events not pushed on the main thread.
  342. *
  343. * \since This function is available since SDL 3.2.0.
  344. *
  345. * \sa SDL_AppInit
  346. * \sa SDL_AppEvent
  347. */
  348. extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppIterate(void *appstate);
  349. /**
  350. * App-implemented event entry point for SDL_MAIN_USE_CALLBACKS apps.
  351. *
  352. * Apps implement this function when using SDL_MAIN_USE_CALLBACKS. If using a
  353. * standard "main" function, you should not supply this.
  354. *
  355. * This function is called as needed by SDL after SDL_AppInit returns
  356. * SDL_APP_CONTINUE. It is called once for each new event.
  357. *
  358. * There is (currently) no guarantee about what thread this will be called
  359. * from; whatever thread pushes an event onto SDL's queue will trigger this
  360. * function. SDL is responsible for pumping the event queue between each call
  361. * to SDL_AppIterate, so in normal operation one should only get events in a
  362. * serial fashion, but be careful if you have a thread that explicitly calls
  363. * SDL_PushEvent. SDL itself will push events to the queue on the main thread.
  364. *
  365. * Events sent to this function are not owned by the app; if you need to save
  366. * the data, you should copy it.
  367. *
  368. * This function should not go into an infinite mainloop; it should handle the
  369. * provided event appropriately and return.
  370. *
  371. * The `appstate` parameter is an optional pointer provided by the app during
  372. * SDL_AppInit(). If the app never provided a pointer, this will be NULL.
  373. *
  374. * If this function returns SDL_APP_CONTINUE, the app will continue normal
  375. * operation, receiving repeated calls to SDL_AppIterate and SDL_AppEvent for
  376. * the life of the program. If this function returns SDL_APP_FAILURE, SDL will
  377. * call SDL_AppQuit and terminate the process with an exit code that reports
  378. * an error to the platform. If it returns SDL_APP_SUCCESS, SDL calls
  379. * SDL_AppQuit and terminates with an exit code that reports success to the
  380. * platform.
  381. *
  382. * \param appstate an optional pointer, provided by the app in SDL_AppInit.
  383. * \param event the new event for the app to examine.
  384. * \returns SDL_APP_FAILURE to terminate with an error, SDL_APP_SUCCESS to
  385. * terminate with success, SDL_APP_CONTINUE to continue.
  386. *
  387. * \threadsafety This function may get called concurrently with
  388. * SDL_AppIterate() or SDL_AppQuit() for events not pushed from
  389. * the main thread.
  390. *
  391. * \since This function is available since SDL 3.2.0.
  392. *
  393. * \sa SDL_AppInit
  394. * \sa SDL_AppIterate
  395. */
  396. extern SDLMAIN_DECLSPEC SDL_AppResult SDLCALL SDL_AppEvent(void *appstate, SDL_Event *event);
  397. /**
  398. * App-implemented deinit entry point for SDL_MAIN_USE_CALLBACKS apps.
  399. *
  400. * Apps implement this function when using SDL_MAIN_USE_CALLBACKS. If using a
  401. * standard "main" function, you should not supply this.
  402. *
  403. * This function is called once by SDL before terminating the program.
  404. *
  405. * This function will be called no matter what, even if SDL_AppInit requests
  406. * termination.
  407. *
  408. * This function should not go into an infinite mainloop; it should
  409. * deinitialize any resources necessary, perform whatever shutdown activities,
  410. * and return.
  411. *
  412. * You do not need to call SDL_Quit() in this function, as SDL will call it
  413. * after this function returns and before the process terminates, but it is
  414. * safe to do so.
  415. *
  416. * The `appstate` parameter is an optional pointer provided by the app during
  417. * SDL_AppInit(). If the app never provided a pointer, this will be NULL. This
  418. * function call is the last time this pointer will be provided, so any
  419. * resources to it should be cleaned up here.
  420. *
  421. * This function is called by SDL on the main thread.
  422. *
  423. * \param appstate an optional pointer, provided by the app in SDL_AppInit.
  424. * \param result the result code that terminated the app (success or failure).
  425. *
  426. * \threadsafety SDL_AppEvent() may get called concurrently with this function
  427. * if other threads that push events are still active.
  428. *
  429. * \since This function is available since SDL 3.2.0.
  430. *
  431. * \sa SDL_AppInit
  432. */
  433. extern SDLMAIN_DECLSPEC void SDLCALL SDL_AppQuit(void *appstate, SDL_AppResult result);
  434. #endif /* SDL_MAIN_USE_CALLBACKS */
  435. /**
  436. * The prototype for the application's main() function
  437. *
  438. * \param argc an ANSI-C style main function's argc.
  439. * \param argv an ANSI-C style main function's argv.
  440. * \returns an ANSI-C main return code; generally 0 is considered successful
  441. * program completion, and small non-zero values are considered
  442. * errors.
  443. *
  444. * \since This datatype is available since SDL 3.2.0.
  445. */
  446. typedef int (SDLCALL *SDL_main_func)(int argc, char *argv[]);
  447. /**
  448. * An app-supplied function for program entry.
  449. *
  450. * Apps do not directly create this function; they should create a standard
  451. * ANSI-C `main` function instead. If SDL needs to insert some startup code
  452. * before `main` runs, or the platform doesn't actually _use_ a function
  453. * called "main", SDL will do some macro magic to redefine `main` to
  454. * `SDL_main` and provide its own `main`.
  455. *
  456. * Apps should include `SDL_main.h` in the same file as their `main` function,
  457. * and they should not use that symbol for anything else in that file, as it
  458. * might get redefined.
  459. *
  460. * This function is only provided by the app if it isn't using
  461. * SDL_MAIN_USE_CALLBACKS.
  462. *
  463. * Program startup is a surprisingly complex topic. Please see
  464. * [README/main-functions](README/main-functions), (or
  465. * docs/README-main-functions.md in the source tree) for a more detailed
  466. * explanation.
  467. *
  468. * \param argc an ANSI-C style main function's argc.
  469. * \param argv an ANSI-C style main function's argv.
  470. * \returns an ANSI-C main return code; generally 0 is considered successful
  471. * program completion, and small non-zero values are considered
  472. * errors.
  473. *
  474. * \threadsafety This is the program entry point.
  475. *
  476. * \since This function is available since SDL 3.2.0.
  477. */
  478. extern SDLMAIN_DECLSPEC int SDLCALL SDL_main(int argc, char *argv[]);
  479. /**
  480. * Circumvent failure of SDL_Init() when not using SDL_main() as an entry
  481. * point.
  482. *
  483. * This function is defined in SDL_main.h, along with the preprocessor rule to
  484. * redefine main() as SDL_main(). Thus to ensure that your main() function
  485. * will not be changed it is necessary to define SDL_MAIN_HANDLED before
  486. * including SDL.h.
  487. *
  488. * \since This function is available since SDL 3.2.0.
  489. *
  490. * \sa SDL_Init
  491. */
  492. extern SDL_DECLSPEC void SDLCALL SDL_SetMainReady(void);
  493. /**
  494. * Initializes and launches an SDL application, by doing platform-specific
  495. * initialization before calling your mainFunction and cleanups after it
  496. * returns, if that is needed for a specific platform, otherwise it just calls
  497. * mainFunction.
  498. *
  499. * You can use this if you want to use your own main() implementation without
  500. * using SDL_main (like when using SDL_MAIN_HANDLED). When using this, you do
  501. * *not* need SDL_SetMainReady().
  502. *
  503. * \param argc the argc parameter from the application's main() function, or 0
  504. * if the platform's main-equivalent has no argc.
  505. * \param argv the argv parameter from the application's main() function, or
  506. * NULL if the platform's main-equivalent has no argv.
  507. * \param mainFunction your SDL app's C-style main(). NOT the function you're
  508. * calling this from! Its name doesn't matter; it doesn't
  509. * literally have to be `main`.
  510. * \param reserved should be NULL (reserved for future use, will probably be
  511. * platform-specific then).
  512. * \returns the return value from mainFunction: 0 on success, otherwise
  513. * failure; SDL_GetError() might have more information on the
  514. * failure.
  515. *
  516. * \threadsafety Generally this is called once, near startup, from the
  517. * process's initial thread.
  518. *
  519. * \since This function is available since SDL 3.2.0.
  520. */
  521. extern SDL_DECLSPEC int SDLCALL SDL_RunApp(int argc, char *argv[], SDL_main_func mainFunction, void *reserved);
  522. /**
  523. * An entry point for SDL's use in SDL_MAIN_USE_CALLBACKS.
  524. *
  525. * Generally, you should not call this function directly. This only exists to
  526. * hand off work into SDL as soon as possible, where it has a lot more control
  527. * and functionality available, and make the inline code in SDL_main.h as
  528. * small as possible.
  529. *
  530. * Not all platforms use this, it's actual use is hidden in a magic
  531. * header-only library, and you should not call this directly unless you
  532. * _really_ know what you're doing.
  533. *
  534. * \param argc standard Unix main argc.
  535. * \param argv standard Unix main argv.
  536. * \param appinit the application's SDL_AppInit function.
  537. * \param appiter the application's SDL_AppIterate function.
  538. * \param appevent the application's SDL_AppEvent function.
  539. * \param appquit the application's SDL_AppQuit function.
  540. * \returns standard Unix main return value.
  541. *
  542. * \threadsafety It is not safe to call this anywhere except as the only
  543. * function call in SDL_main.
  544. *
  545. * \since This function is available since SDL 3.2.0.
  546. */
  547. extern SDL_DECLSPEC int SDLCALL SDL_EnterAppMainCallbacks(int argc, char *argv[], SDL_AppInit_func appinit, SDL_AppIterate_func appiter, SDL_AppEvent_func appevent, SDL_AppQuit_func appquit);
  548. #if defined(SDL_PLATFORM_WINDOWS)
  549. /**
  550. * Register a win32 window class for SDL's use.
  551. *
  552. * This can be called to set the application window class at startup. It is
  553. * safe to call this multiple times, as long as every call is eventually
  554. * paired with a call to SDL_UnregisterApp, but a second registration attempt
  555. * while a previous registration is still active will be ignored, other than
  556. * to increment a counter.
  557. *
  558. * Most applications do not need to, and should not, call this directly; SDL
  559. * will call it when initializing the video subsystem.
  560. *
  561. * \param name the window class name, in UTF-8 encoding. If NULL, SDL
  562. * currently uses "SDL_app" but this isn't guaranteed.
  563. * \param style the value to use in WNDCLASSEX::style. If `name` is NULL, SDL
  564. * currently uses `(CS_BYTEALIGNCLIENT | CS_OWNDC)` regardless of
  565. * what is specified here.
  566. * \param hInst the HINSTANCE to use in WNDCLASSEX::hInstance. If zero, SDL
  567. * will use `GetModuleHandle(NULL)` instead.
  568. * \returns true on success or false on failure; call SDL_GetError() for more
  569. * information.
  570. *
  571. * \since This function is available since SDL 3.2.0.
  572. */
  573. extern SDL_DECLSPEC bool SDLCALL SDL_RegisterApp(const char *name, Uint32 style, void *hInst);
  574. /**
  575. * Deregister the win32 window class from an SDL_RegisterApp call.
  576. *
  577. * This can be called to undo the effects of SDL_RegisterApp.
  578. *
  579. * Most applications do not need to, and should not, call this directly; SDL
  580. * will call it when deinitializing the video subsystem.
  581. *
  582. * It is safe to call this multiple times, as long as every call is eventually
  583. * paired with a prior call to SDL_RegisterApp. The window class will only be
  584. * deregistered when the registration counter in SDL_RegisterApp decrements to
  585. * zero through calls to this function.
  586. *
  587. * \since This function is available since SDL 3.2.0.
  588. */
  589. extern SDL_DECLSPEC void SDLCALL SDL_UnregisterApp(void);
  590. #endif /* defined(SDL_PLATFORM_WINDOWS) */
  591. /**
  592. * Callback from the application to let the suspend continue.
  593. *
  594. * This function is only needed for Xbox GDK support; all other platforms will
  595. * do nothing and set an "unsupported" error message.
  596. *
  597. * \since This function is available since SDL 3.2.0.
  598. */
  599. extern SDL_DECLSPEC void SDLCALL SDL_GDKSuspendComplete(void);
  600. #ifdef __cplusplus
  601. }
  602. #endif
  603. #include <SDL3/SDL_close_code.h>
  604. #if !defined(SDL_MAIN_HANDLED) && !defined(SDL_MAIN_NOIMPL)
  605. /* include header-only SDL_main implementations */
  606. #if defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE)
  607. /* platforms which main (-equivalent) can be implemented in plain C */
  608. #include <SDL3/SDL_main_impl.h>
  609. #endif
  610. #endif
  611. #endif /* SDL_main_h_ */