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