Browse Source

main: Indented SDL_main headers for readability, removed SDL2 compat macros.

Specifically, SDL_WinRTRunApp, SDL_UIKitRunApp, and SDL_GDKRunApp macros were
removed, as likely unnecessary to SDL3 users. A note was added to the
migration doc about how to roll replacements. These are not going into
SDL_oldnames.h.

Fixes #8245.
Ryan C. Gordon 1 year ago
parent
commit
8814095aa8
3 changed files with 294 additions and 308 deletions
  1. 9 1
      docs/README-migration.md
  2. 112 133
      include/SDL3/SDL_main.h
  3. 173 174
      include/SDL3/SDL_main_impl.h

+ 9 - 1
docs/README-migration.md

@@ -861,7 +861,15 @@ SDL3 doesn't have a static libSDLmain to link against anymore.
 Instead SDL_main.h is now a header-only library **and not included by SDL.h anymore**.
 
 Using it is really simple: Just `#include <SDL3/SDL_main.h>` in the source file with your standard
-`int main(int argc, char* argv[])` function.
+`int main(int argc, char* argv[])` function. See docs/README-main-functions.md for details.
+
+Several platform-specific entry point functions have been removed as unnecessary. If for some reason you explicitly need them, here are easy replacements:
+
+```c
+#define SDL_WinRTRunApp(MAIN_FUNC, RESERVED)  SDL_RunApp(0, NULL, MAIN_FUNC, RESERVED)
+#define SDL_UIKitRunApp(ARGC, ARGV, MAIN_FUNC)  SDL_RunApp(ARGC, ARGV, MAIN_FUNC, NULL)
+#define SDL_GDKRunApp(MAIN_FUNC, RESERVED)  SDL_RunApp(0, NULL, MAIN_FUNC, RESERVED)
+```
 
 ## SDL_metal.h
 

+ 112 - 133
include/SDL3/SDL_main.h

@@ -41,94 +41,93 @@
  */
 
 #ifndef SDL_MAIN_HANDLED
-#ifdef SDL_PLATFORM_WIN32
-/* On Windows SDL provides WinMain(), which parses the command line and passes
-   the arguments to your main function.
-
-   If you provide your own WinMain(), you may define SDL_MAIN_HANDLED
- */
-#define SDL_MAIN_AVAILABLE
-
-#elif defined(SDL_PLATFORM_WINRT)
-/* On WinRT, SDL provides a main function that initializes CoreApplication,
-   creating an instance of IFrameworkView in the process.
-
-   Ideally, #include'ing SDL_main.h is enough to get a main() function working.
-   However, that requires the source file your main() is in to be compiled
-   as C++ *and* with the /ZW compiler flag. If that's not feasible, add an
-   otherwise empty .cpp file that only contains `#include <SDL3/SDL_main.h>`
-   and build that with /ZW (still include SDL_main.h in your other file with main()!).
-   In XAML apps, instead the function SDL_RunApp() must be called with a pointer
-   to the Direct3D-hosted XAML control passed in as the "reserved" argument.
-*/
-#define SDL_MAIN_NEEDED
-
-#elif defined(SDL_PLATFORM_GDK)
-/* On GDK, SDL provides a main function that initializes the game runtime.
-
-   If you prefer to write your own WinMain-function instead of having SDL
-   provide one that calls your main() function,
-   #define SDL_MAIN_HANDLED before #include'ing SDL_main.h
-   and call the SDL_RunApp function from your entry point.
-*/
-#define SDL_MAIN_NEEDED
-
-#elif defined(SDL_PLATFORM_IOS)
-/* On iOS SDL provides a main function that creates an application delegate
-   and starts the iOS application run loop.
-
-   To use it, just #include SDL_main.h in the source file that contains your
-   main() function.
-
-   See src/video/uikit/SDL_uikitappdelegate.m for more details.
- */
-#define SDL_MAIN_NEEDED
-
-#elif defined(SDL_PLATFORM_ANDROID)
-/* On Android SDL provides a Java class in SDLActivity.java that is the
-   main activity entry point.
-
-   See docs/README-android.md for more details on extending that class.
- */
-#define SDL_MAIN_NEEDED
-
-/* We need to export SDL_main so it can be launched from Java */
-#define SDLMAIN_DECLSPEC    DECLSPEC
-
-#elif defined(SDL_PLATFORM_PSP)
-/* On PSP SDL provides a main function that sets the module info,
-   activates the GPU and starts the thread required to be able to exit
-   the software.
-
-   If you provide this yourself, you may define SDL_MAIN_HANDLED
- */
-#define SDL_MAIN_AVAILABLE
-
-#elif defined(SDL_PLATFORM_PS2)
-#define SDL_MAIN_AVAILABLE
-
-#define SDL_PS2_SKIP_IOP_RESET() \
-   void reset_IOP(); \
-   void reset_IOP() {}
-
-#elif defined(SDL_PLATFORM_3DS)
-/*
-  On N3DS, SDL provides a main function that sets up the screens
-  and storage.
-
-  If you provide this yourself, you may define SDL_MAIN_HANDLED
-*/
-#define SDL_MAIN_AVAILABLE
-
-#elif defined(SDL_PLATFORM_NGAGE)
-
-/*
-   TODO: not sure if it should be SDL_MAIN_NEEDED, in SDL2 ngage had a
-        main implementation, but wasn't mentioned in SDL_main.h
- */
-#define SDL_MAIN_AVAILABLE
-
-#endif
+    #ifdef SDL_PLATFORM_WIN32
+        /* On Windows SDL provides WinMain(), which parses the command line and passes
+           the arguments to your main function.
+
+           If you provide your own WinMain(), you may define SDL_MAIN_HANDLED
+         */
+        #define SDL_MAIN_AVAILABLE
+
+    #elif defined(SDL_PLATFORM_WINRT)
+        /* On WinRT, SDL provides a main function that initializes CoreApplication,
+           creating an instance of IFrameworkView in the process.
+
+           Ideally, #include'ing SDL_main.h is enough to get a main() function working.
+           However, that requires the source file your main() is in to be compiled
+           as C++ *and* with the /ZW compiler flag. If that's not feasible, add an
+           otherwise empty .cpp file that only contains `#include <SDL3/SDL_main.h>`
+           and build that with /ZW (still include SDL_main.h in your other file with main()!).
+           In XAML apps, instead the function SDL_RunApp() must be called with a pointer
+           to the Direct3D-hosted XAML control passed in as the "reserved" argument.
+        */
+        #define SDL_MAIN_NEEDED
+
+    #elif defined(SDL_PLATFORM_GDK)
+        /* On GDK, SDL provides a main function that initializes the game runtime.
+
+           If you prefer to write your own WinMain-function instead of having SDL
+           provide one that calls your main() function,
+           #define SDL_MAIN_HANDLED before #include'ing SDL_main.h
+           and call the SDL_RunApp function from your entry point.
+        */
+        #define SDL_MAIN_NEEDED
+
+    #elif defined(SDL_PLATFORM_IOS)
+        /* On iOS SDL provides a main function that creates an application delegate
+           and starts the iOS application run loop.
+
+           To use it, just #include SDL_main.h in the source file that contains your
+           main() function.
+
+           See src/video/uikit/SDL_uikitappdelegate.m for more details.
+         */
+        #define SDL_MAIN_NEEDED
+
+    #elif defined(SDL_PLATFORM_ANDROID)
+        /* On Android SDL provides a Java class in SDLActivity.java that is the
+           main activity entry point.
+
+           See docs/README-android.md for more details on extending that class.
+         */
+        #define SDL_MAIN_NEEDED
+
+        /* We need to export SDL_main so it can be launched from Java */
+        #define SDLMAIN_DECLSPEC    DECLSPEC
+
+    #elif defined(SDL_PLATFORM_PSP)
+        /* On PSP SDL provides a main function that sets the module info,
+           activates the GPU and starts the thread required to be able to exit
+           the software.
+
+           If you provide this yourself, you may define SDL_MAIN_HANDLED
+         */
+        #define SDL_MAIN_AVAILABLE
+
+    #elif defined(SDL_PLATFORM_PS2)
+        #define SDL_MAIN_AVAILABLE
+
+        #define SDL_PS2_SKIP_IOP_RESET() \
+           void reset_IOP(); \
+           void reset_IOP() {}
+
+    #elif defined(SDL_PLATFORM_3DS)
+        /*
+          On N3DS, SDL provides a main function that sets up the screens
+          and storage.
+
+          If you provide this yourself, you may define SDL_MAIN_HANDLED
+        */
+        #define SDL_MAIN_AVAILABLE
+
+    #elif defined(SDL_PLATFORM_NGAGE)
+        /*
+        TODO: not sure if it should be SDL_MAIN_NEEDED, in SDL2 ngage had a
+                main implementation, but wasn't mentioned in SDL_main.h
+         */
+        #define SDL_MAIN_AVAILABLE
+
+    #endif
 #endif /* SDL_MAIN_HANDLED */
 
 #ifndef SDLMAIN_DECLSPEC
@@ -151,7 +150,7 @@
  */
 
 #if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE) || defined(SDL_MAIN_USE_CALLBACKS)
-#define main    SDL_main
+#define main SDL_main
 #endif
 
 #include <SDL3/SDL_begin_code.h>
@@ -470,26 +469,8 @@ extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
 
 #endif /* defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK) */
 
-
-#ifdef SDL_PLATFORM_WINRT
-
-/* for compatibility with SDL2's function of this name */
-#define SDL_WinRTRunApp(MAIN_FUNC, RESERVED)  SDL_RunApp(0, NULL, MAIN_FUNC, RESERVED)
-
-#endif /* SDL_PLATFORM_WINRT */
-
-#ifdef SDL_PLATFORM_IOS
-
-/* for compatibility with SDL2's function of this name */
-#define SDL_UIKitRunApp(ARGC, ARGV, MAIN_FUNC)  SDL_RunApp(ARGC, ARGV, MAIN_FUNC, NULL)
-
-#endif /* SDL_PLATFORM_IOS */
-
 #ifdef SDL_PLATFORM_GDK
 
-/* for compatibility with SDL2's function of this name */
-#define SDL_GDKRunApp(MAIN_FUNC, RESERVED)  SDL_RunApp(0, NULL, MAIN_FUNC, RESERVED)
-
 /**
  * Callback from the application to let the suspend continue.
  *
@@ -506,31 +487,29 @@ extern DECLSPEC void SDLCALL SDL_GDKSuspendComplete(void);
 #include <SDL3/SDL_close_code.h>
 
 #if !defined(SDL_MAIN_HANDLED) && !defined(SDL_MAIN_NOIMPL)
-/* include header-only SDL_main implementations */
-#if defined(SDL_MAIN_USE_CALLBACKS) \
-    || defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS) \
-    || defined(SDL_PLATFORM_3DS) || defined(SDL_PLATFORM_NGAGE) || defined(SDL_PLATFORM_PS2) || defined(SDL_PLATFORM_PSP)
-
-/* platforms which main (-equivalent) can be implemented in plain C */
-#include <SDL3/SDL_main_impl.h>
-
-#elif defined(SDL_PLATFORM_WINRT) /* C++ platforms */
-
-#ifdef __cplusplus
-#include <SDL3/SDL_main_impl.h>
-#else
-/* Note: to get rid of the following warning, you can #define SDL_MAIN_NOIMPL before including SDL_main.h
- *  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()!
- */
-#ifdef _MSC_VER
-#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>")
-#elif defined(__GNUC__) /* gcc, clang, mingw and compatible are matched by this and have #warning */
-#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>"
-#endif /* __GNUC__ */
-#endif /* __cplusplus */
-
-#endif /* C++ platforms like SDL_PLATFORM_WINRT etc */
-
-#endif /* SDL_MAIN_HANDLED */
+    /* include header-only SDL_main implementations */
+    #if defined(SDL_MAIN_USE_CALLBACKS) \
+        || defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS) \
+        || defined(SDL_PLATFORM_3DS) || defined(SDL_PLATFORM_NGAGE) || defined(SDL_PLATFORM_PS2) || defined(SDL_PLATFORM_PSP)
+
+        /* platforms which main (-equivalent) can be implemented in plain C */
+        #include <SDL3/SDL_main_impl.h>
+
+    #elif defined(SDL_PLATFORM_WINRT) /* C++ platforms */
+        #ifdef __cplusplus
+        #include <SDL3/SDL_main_impl.h>
+        #else
+            /* Note: to get rid of the following warning, you can #define SDL_MAIN_NOIMPL before including SDL_main.h
+             *  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()!
+             */
+            #ifdef _MSC_VER
+                #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>")
+            #elif defined(__GNUC__) /* gcc, clang, mingw and compatible are matched by this and have #warning */
+                #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>"
+            #endif /* __GNUC__ */
+        #endif /* __cplusplus */
+
+    #endif /* C++ platforms like SDL_PLATFORM_WINRT etc */
+#endif
 
 #endif /* SDL_main_h_ */

+ 173 - 174
include/SDL3/SDL_main_impl.h

@@ -35,181 +35,180 @@
    and main() is implemented in plain C */
 #if !defined(SDL_MAIN_HANDLED) && !defined(SDL_MAIN_NOIMPL)
 
-/* the implementations below must be able to use the implement real main(), nothing renamed
-   (the user's main() will be renamed to SDL_main so it can be called from here) */
-#ifdef main
-#  undef main
-#endif /* main */
+    /* the implementations below must be able to use the implement real main(), nothing renamed
+       (the user's main() will be renamed to SDL_main so it can be called from here) */
+    #ifdef main
+        #undef main
+    #endif
 
-#ifdef SDL_MAIN_USE_CALLBACKS
-
-#if 0
-    /* currently there are no platforms that _need_ a magic entry point here
-       for callbacks, but if one shows up, implement it here. */
-
-#else /* use a standard SDL_main, which the app SHOULD NOT ALSO SUPPLY. */
-
-/* this define makes the normal SDL_main entry point stuff work...we just provide SDL_main() instead of the app. */
-#define SDL_MAIN_CALLBACK_STANDARD 1
-
-int SDL_main(int argc, char **argv)
-{
-    return SDL_EnterAppMainCallbacks(argc, argv, SDL_AppInit, SDL_AppIterate, SDL_AppEvent, SDL_AppQuit);
-}
-
-#endif  /* platform-specific tests */
-
-#endif  /* SDL_MAIN_USE_CALLBACKS */
-
-
-/* set up the usual SDL_main stuff if we're not using callbacks or if we are but need the normal entry point. */
-#if !defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_CALLBACK_STANDARD)
-
-#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
-
-/* these defines/typedefs are needed for the WinMain() definition */
-#ifndef WINAPI
-#define WINAPI __stdcall
-#endif
-
-typedef struct HINSTANCE__ * HINSTANCE;
-typedef char* LPSTR;
-typedef wchar_t* PWSTR;
-
-/* The VC++ compiler needs main/wmain defined, but not for GDK */
-#if defined(_MSC_VER) && !defined(SDL_PLATFORM_GDK)
-
-/* This is where execution begins [console apps] */
-#if defined( UNICODE ) && UNICODE
-int wmain(int argc, wchar_t *wargv[], wchar_t *wenvp)
-{
-    (void)argc;
-    (void)wargv;
-    (void)wenvp;
-    return SDL_RunApp(0, NULL, SDL_main, NULL);
-}
-#else /* ANSI */
-int main(int argc, char *argv[])
-{
-    (void)argc;
-    (void)argv;
-    return SDL_RunApp(0, NULL, SDL_main, NULL);
-}
-#endif /* UNICODE */
-
-#endif /* _MSC_VER && ! SDL_PLATFORM_GDK */
-
-/* This is where execution begins [windowed apps and GDK] */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if defined( UNICODE ) && UNICODE
-int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, PWSTR szCmdLine, int sw)
-#else /* ANSI */
-int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
-#endif
-{
-    (void)hInst;
-    (void)hPrev;
-    (void)szCmdLine;
-    (void)sw;
-    return SDL_RunApp(0, NULL, SDL_main, NULL);
-}
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-/* end of SDL_PLATFORM_WIN32 and SDL_PLATFORM_GDK impls */
-#elif defined(SDL_PLATFORM_WINRT)
-
-/* WinRT main based on SDL_winrt_main_NonXAML.cpp, placed in the public domain by David Ludwig  3/13/14 */
-
-#include <wrl.h>
-
-/* At least one file in any SDL/WinRT app appears to require compilation
-   with C++/CX, otherwise a Windows Metadata file won't get created, and
-   an APPX0702 build error can appear shortly after linking.
-
-   The following set of preprocessor code forces this file to be compiled
-   as C++/CX, which appears to cause Visual C++ 2012's build tools to
-   create this .winmd file, and will help allow builds of SDL/WinRT apps
-   to proceed without error.
-
-   If other files in an app's project enable C++/CX compilation, then it might
-   be possible for the .cpp file including SDL_main.h to be compiled without /ZW,
-   for Visual C++'s build tools to create a winmd file, and for the app to
-   build without APPX0702 errors.  In this case, if
-   SDL_WINRT_METADATA_FILE_AVAILABLE is defined as a C/C++ macro, then
-   the #error (to force C++/CX compilation) will be disabled.
-
-   Please note that /ZW can be specified on a file-by-file basis.  To do this,
-   right click on the file in Visual C++, click Properties, then change the
-   setting through the dialog that comes up.
-*/
-#ifndef SDL_WINRT_METADATA_FILE_AVAILABLE
-#if !defined(__cplusplus) || !defined(__cplusplus_winrt)
-#error The C++ file that includes SDL_main.h must be compiled as C++ code with /ZW, otherwise build errors due to missing .winmd files can occur.
-#endif
-#endif
-
-/* Prevent MSVC++ from warning about threading models when defining our
-   custom WinMain.  The threading model will instead be set via a direct
-   call to Windows::Foundation::Initialize (rather than via an attributed
-   function).
-
-   To note, this warning (C4447) does not seem to come up unless this file
-   is compiled with C++/CX enabled (via the /ZW compiler flag).
-*/
-#ifdef _MSC_VER
-#pragma warning(disable : 4447)
-#endif
-
-/* Make sure the function to initialize the Windows Runtime gets linked in. */
-#ifdef _MSC_VER
-#pragma comment(lib, "runtimeobject.lib")
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
-{
-    return SDL_RunApp(0, NULL, SDL_main, NULL);
-}
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-/* end of WinRT impl */
-#elif defined(SDL_PLATFORM_NGAGE)
-
-/* same typedef as in ngage SDKs e32def.h */
-typedef signed int TInt;
-/* TODO: if it turns out that this only works when built as C++,
-         move SDL_PLATFORM_NGAGE into the C++ section in SDL_main.h */
-TInt E32Main()
-{
-    return SDL_RunApp(0, NULL, SDL_main, NULL);
-}
-
-/* end of SDL_PLATFORM_NGAGE impl */
-
-#else /* platforms that use a standard main() and just call SDL_RunApp(), like iOS and 3DS */
-
-int main(int argc, char *argv[])
-{
-    return SDL_RunApp(argc, argv, SDL_main, NULL);
-}
-
-/* end of impls for standard-conforming platforms */
-
-#endif /* SDL_PLATFORM_WIN32 etc */
-
-#endif /* !defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_CALLBACK_STANDARD) */
-
-/* rename users main() function to SDL_main() so it can be called from the wrappers above */
-#define main    SDL_main
+    #ifdef SDL_MAIN_USE_CALLBACKS
+
+        #if 0
+            /* currently there are no platforms that _need_ a magic entry point here
+               for callbacks, but if one shows up, implement it here. */
+
+        #else /* use a standard SDL_main, which the app SHOULD NOT ALSO SUPPLY. */
+
+            /* this define makes the normal SDL_main entry point stuff work...we just provide SDL_main() instead of the app. */
+            #define SDL_MAIN_CALLBACK_STANDARD 1
+
+            int SDL_main(int argc, char **argv)
+            {
+                return SDL_EnterAppMainCallbacks(argc, argv, SDL_AppInit, SDL_AppIterate, SDL_AppEvent, SDL_AppQuit);
+            }
+
+        #endif  /* platform-specific tests */
+
+    #endif  /* SDL_MAIN_USE_CALLBACKS */
+
+
+    /* set up the usual SDL_main stuff if we're not using callbacks or if we are but need the normal entry point. */
+    #if !defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_CALLBACK_STANDARD)
+
+        #if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
+
+            /* these defines/typedefs are needed for the WinMain() definition */
+            #ifndef WINAPI
+                #define WINAPI __stdcall
+            #endif
+
+            typedef struct HINSTANCE__ * HINSTANCE;
+            typedef char* LPSTR;
+            typedef wchar_t* PWSTR;
+
+            /* The VC++ compiler needs main/wmain defined, but not for GDK */
+            #if defined(_MSC_VER) && !defined(SDL_PLATFORM_GDK)
+
+                /* This is where execution begins [console apps] */
+                #if defined( UNICODE ) && UNICODE
+                    int wmain(int argc, wchar_t *wargv[], wchar_t *wenvp)
+                    {
+                        (void)argc;
+                        (void)wargv;
+                        (void)wenvp;
+                        return SDL_RunApp(0, NULL, SDL_main, NULL);
+                    }
+                #else /* ANSI */
+                    int main(int argc, char *argv[])
+                    {
+                        (void)argc;
+                        (void)argv;
+                        return SDL_RunApp(0, NULL, SDL_main, NULL);
+                    }
+                #endif /* UNICODE */
+
+            #endif /* _MSC_VER && ! SDL_PLATFORM_GDK */
+
+            /* This is where execution begins [windowed apps and GDK] */
+
+            #ifdef __cplusplus
+            extern "C" {
+            #endif
+
+            #if defined( UNICODE ) && UNICODE
+            int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, PWSTR szCmdLine, int sw)
+            #else /* ANSI */
+            int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
+            #endif
+            {
+                (void)hInst;
+                (void)hPrev;
+                (void)szCmdLine;
+                (void)sw;
+                return SDL_RunApp(0, NULL, SDL_main, NULL);
+            }
+
+            #ifdef __cplusplus
+            } /* extern "C" */
+            #endif
+
+            /* end of SDL_PLATFORM_WIN32 and SDL_PLATFORM_GDK impls */
+
+        #elif defined(SDL_PLATFORM_WINRT)
+
+            /* WinRT main based on SDL_winrt_main_NonXAML.cpp, placed in the public domain by David Ludwig  3/13/14 */
+
+            #include <wrl.h>
+
+            /* At least one file in any SDL/WinRT app appears to require compilation
+               with C++/CX, otherwise a Windows Metadata file won't get created, and
+               an APPX0702 build error can appear shortly after linking.
+
+               The following set of preprocessor code forces this file to be compiled
+               as C++/CX, which appears to cause Visual C++ 2012's build tools to
+               create this .winmd file, and will help allow builds of SDL/WinRT apps
+               to proceed without error.
+
+               If other files in an app's project enable C++/CX compilation, then it might
+               be possible for the .cpp file including SDL_main.h to be compiled without /ZW,
+               for Visual C++'s build tools to create a winmd file, and for the app to
+               build without APPX0702 errors.  In this case, if
+               SDL_WINRT_METADATA_FILE_AVAILABLE is defined as a C/C++ macro, then
+               the #error (to force C++/CX compilation) will be disabled.
+
+               Please note that /ZW can be specified on a file-by-file basis.  To do this,
+               right click on the file in Visual C++, click Properties, then change the
+               setting through the dialog that comes up.
+            */
+            #ifndef SDL_WINRT_METADATA_FILE_AVAILABLE
+                #if !defined(__cplusplus) || !defined(__cplusplus_winrt)
+                    #error The C++ file that includes SDL_main.h must be compiled as C++ code with /ZW, otherwise build errors due to missing .winmd files can occur.
+                #endif
+            #endif
+
+            /* Prevent MSVC++ from warning about threading models when defining our
+               custom WinMain.  The threading model will instead be set via a direct
+               call to Windows::Foundation::Initialize (rather than via an attributed
+               function).
+
+               To note, this warning (C4447) does not seem to come up unless this file
+               is compiled with C++/CX enabled (via the /ZW compiler flag).
+            */
+            #ifdef _MSC_VER
+            #pragma warning(disable : 4447)
+            /* Make sure the function to initialize the Windows Runtime gets linked in. */
+            #pragma comment(lib, "runtimeobject.lib")
+            #endif
+
+            #ifdef __cplusplus
+            extern "C" {
+            #endif
+            int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
+            {
+                return SDL_RunApp(0, NULL, SDL_main, NULL);
+            }
+            #ifdef __cplusplus
+            } /* extern "C" */
+            #endif
+
+            /* end of WinRT impl */
+
+        #elif defined(SDL_PLATFORM_NGAGE)
+            /* same typedef as in ngage SDKs e32def.h */
+            typedef signed int TInt;
+            /* TODO: if it turns out that this only works when built as C++,
+                     move SDL_PLATFORM_NGAGE into the C++ section in SDL_main.h */
+            TInt E32Main()
+            {
+                return SDL_RunApp(0, NULL, SDL_main, NULL);
+            }
+
+            /* end of SDL_PLATFORM_NGAGE impl */
+
+        #else /* platforms that use a standard main() and just call SDL_RunApp(), like iOS and 3DS */
+            int main(int argc, char *argv[])
+            {
+                return SDL_RunApp(argc, argv, SDL_main, NULL);
+            }
+
+            /* end of impls for standard-conforming platforms */
+
+        #endif /* SDL_PLATFORM_WIN32 etc */
+
+    #endif /* !defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_CALLBACK_STANDARD) */
+
+    /* rename users main() function to SDL_main() so it can be called from the wrappers above */
+    #define main    SDL_main
 
 #endif /* SDL_MAIN_HANDLED */