SDL_winrt_main_NonXAML.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. SDL_winrt_main_NonXAML.cpp, placed in the public domain by David Ludwig 3/13/14
  3. */
  4. #include "SDL_main.h"
  5. #include <wrl.h>
  6. /* At least one file in any SDL/WinRT app appears to require compilation
  7. with C++/CX, otherwise a Windows Metadata file won't get created, and
  8. an APPX0702 build error can appear shortly after linking.
  9. The following set of preprocessor code forces this file to be compiled
  10. as C++/CX, which appears to cause Visual C++ 2012's build tools to
  11. create this .winmd file, and will help allow builds of SDL/WinRT apps
  12. to proceed without error.
  13. If other files in an app's project enable C++/CX compilation, then it might
  14. be possible for SDL_winrt_main_NonXAML.cpp to be compiled without /ZW,
  15. for Visual C++'s build tools to create a winmd file, and for the app to
  16. build without APPX0702 errors. In this case, if
  17. SDL_WINRT_METADATA_FILE_AVAILABLE is defined as a C/C++ macro, then
  18. the #error (to force C++/CX compilation) will be disabled.
  19. Please note that /ZW can be specified on a file-by-file basis. To do this,
  20. right click on the file in Visual C++, click Properties, then change the
  21. setting through the dialog that comes up.
  22. */
  23. #ifndef SDL_WINRT_METADATA_FILE_AVAILABLE
  24. #ifndef __cplusplus_winrt
  25. #error SDL_winrt_main_NonXAML.cpp must be compiled with /ZW, otherwise build errors due to missing .winmd files can occur.
  26. #endif
  27. #endif
  28. /* Prevent MSVC++ from warning about threading models when defining our
  29. custom WinMain. The threading model will instead be set via a direct
  30. call to Windows::Foundation::Initialize (rather than via an attributed
  31. function).
  32. To note, this warning (C4447) does not seem to come up unless this file
  33. is compiled with C++/CX enabled (via the /ZW compiler flag).
  34. */
  35. #ifdef _MSC_VER
  36. #pragma warning(disable:4447)
  37. #endif
  38. /* Make sure the function to initialize the Windows Runtime gets linked in. */
  39. #ifdef _MSC_VER
  40. #pragma comment(lib, "runtimeobject.lib")
  41. #endif
  42. int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  43. {
  44. if (FAILED(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED))) {
  45. return 1;
  46. }
  47. SDL_WinRTRunApp(SDL_main, NULL);
  48. return 0;
  49. }