src/main/winrt/SDL_winrt_main_NonXAML.cpp
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sat, 06 Sep 2014 23:20:14 +0200
changeset 9125 e004bdb812ce
parent 8619 a4538a64b9bb
child 11661 bd1495ebc979
permissions -rw-r--r--
Fixed example in header file.

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