Path: blob/master/thirdparty/sdl/include/SDL3/SDL_main_impl.h
9912 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/* WIKI CATEGORY: Main */2223#ifndef SDL_main_impl_h_24#define SDL_main_impl_h_2526#ifndef SDL_main_h_27#error "This header should not be included directly, but only via SDL_main.h!"28#endif2930/* if someone wants to include SDL_main.h but doesn't want the main handing magic,31(maybe to call SDL_RegisterApp()) they can #define SDL_MAIN_HANDLED first.32SDL_MAIN_NOIMPL is for SDL-internal usage (only affects implementation,33not definition of SDL_MAIN_AVAILABLE etc in SDL_main.h) and if the user wants34to have the SDL_main implementation (from this header) in another source file35than their main() function, for example if SDL_main requires C++36and main() is implemented in plain C */37#if !defined(SDL_MAIN_HANDLED) && !defined(SDL_MAIN_NOIMPL)3839/* the implementations below must be able to use the implement real main(), nothing renamed40(the user's main() will be renamed to SDL_main so it can be called from here) */41#ifdef main42#undef main43#endif4445#ifdef SDL_MAIN_USE_CALLBACKS4647#if 048/* currently there are no platforms that _need_ a magic entry point here49for callbacks, but if one shows up, implement it here. */5051#else /* use a standard SDL_main, which the app SHOULD NOT ALSO SUPPLY. */5253/* this define makes the normal SDL_main entry point stuff work...we just provide SDL_main() instead of the app. */54#define SDL_MAIN_CALLBACK_STANDARD 15556int SDL_main(int argc, char **argv)57{58return SDL_EnterAppMainCallbacks(argc, argv, SDL_AppInit, SDL_AppIterate, SDL_AppEvent, SDL_AppQuit);59}6061#endif /* platform-specific tests */6263#endif /* SDL_MAIN_USE_CALLBACKS */646566/* set up the usual SDL_main stuff if we're not using callbacks or if we are but need the normal entry point,67unless the real entry point needs to be somewhere else entirely, like Android where it's in Java code */68#if (!defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_CALLBACK_STANDARD)) && !defined(SDL_MAIN_EXPORTED)6970#if defined(SDL_PLATFORM_PRIVATE_MAIN)71/* Private platforms may have their own ideas about entry points. */72#include "SDL_main_impl_private.h"7374#elif defined(SDL_PLATFORM_WINDOWS)7576/* these defines/typedefs are needed for the WinMain() definition */77#ifndef WINAPI78#define WINAPI __stdcall79#endif8081typedef struct HINSTANCE__ * HINSTANCE;82typedef char *LPSTR;83typedef wchar_t *PWSTR;8485/* The VC++ compiler needs main/wmain defined, but not for GDK */86#if defined(_MSC_VER) && !defined(SDL_PLATFORM_GDK)8788/* This is where execution begins [console apps] */89#if defined(UNICODE) && UNICODE90int wmain(int argc, wchar_t *wargv[], wchar_t *wenvp)91{92(void)argc;93(void)wargv;94(void)wenvp;95return SDL_RunApp(0, NULL, SDL_main, NULL);96}97#else /* ANSI */98int main(int argc, char *argv[])99{100(void)argc;101(void)argv;102return SDL_RunApp(0, NULL, SDL_main, NULL);103}104#endif /* UNICODE */105106#endif /* _MSC_VER && ! SDL_PLATFORM_GDK */107108/* This is where execution begins [windowed apps and GDK] */109110#ifdef __cplusplus111extern "C" {112#endif113114#if defined(UNICODE) && UNICODE115int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, PWSTR szCmdLine, int sw)116#else /* ANSI */117int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)118#endif119{120(void)hInst;121(void)hPrev;122(void)szCmdLine;123(void)sw;124return SDL_RunApp(0, NULL, SDL_main, NULL);125}126127#ifdef __cplusplus128} /* extern "C" */129#endif130131/* end of SDL_PLATFORM_WINDOWS impls */132133#else /* platforms that use a standard main() and just call SDL_RunApp(), like iOS and 3DS */134int main(int argc, char *argv[])135{136return SDL_RunApp(argc, argv, SDL_main, NULL);137}138139/* end of impls for standard-conforming platforms */140141#endif /* SDL_PLATFORM_WIN32 etc */142143#endif /* !defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_CALLBACK_STANDARD) */144145/* rename users main() function to SDL_main() so it can be called from the wrappers above */146#define main SDL_main147148#endif /* SDL_MAIN_HANDLED */149150#endif /* SDL_main_impl_h_ */151152153