WinRT: made SDL_winrt_main.cpp not have to be compiled as C++/CX (via the /ZW compiler flag) This file can still be compiled as C++/CX, however that is now optional/not-required.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/src/main/winrt/SDL_winrt_main.cpp b/src/main/winrt/SDL_winrt_main.cpp
index 9cc046d..b06def8 100644
--- a/src/main/winrt/SDL_winrt_main.cpp
+++ b/src/main/winrt/SDL_winrt_main.cpp
@@ -1,14 +1,36 @@
-//#include "pch.h"
+#include <wrl.h>
-// The app's C-style main will be passed into SDL.dll as a function
-// pointer, and called at the appropriate time.
+/* The app's C-style main will be passed into SDL.dll as a function
+ pointer, and called at the appropriate time.
+*/
typedef int (*SDLmain_MainFunction)(int, char **);
extern __declspec(dllimport) int SDL_WinRT_RunApplication(SDLmain_MainFunction mainFunction);
extern "C" int SDL_main(int, char **);
-[Platform::MTAThread]
-int main(Platform::Array<Platform::String^>^)
+/* 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
+
+int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
- return SDL_WinRT_RunApplication(SDL_main);
+ if (FAILED(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED))) {
+ return 1;
+ }
+
+ SDL_WinRT_RunApplication(SDL_main);
+ return 0;
}