SDL_main.h 26 KB

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