SDL_winrt_main_NonXAML.cpp 2.3 KB

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