src/main/windows/SDL_windows_main.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 28 Nov 2014 04:51:33 -0800
changeset 9246 a761913e5e91
parent 9016 648dbad92045
child 9365 2e624f24d1af
permissions -rw-r--r--
Fixed bug 2786 - "UCS-2-INTERNAL" iconv encoding is not supported everywhere, use UTF-16LE instead Jonas Kulla src/main/windows/SDL_windows_main.c:137: cmdline = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(text), (SDL_wcslen(text)+1)*sizeof(WCHAR)); I'm trying to compile an SDL2 application for windows using the mingw-w64 32bit toolchain provided by my distro (Fedora 19). However, even the simplest test program that does nothing at all fails to startup with a "Fatal error - out of memory" message because the mingw iconv library provided by my distro does not support the "UCS-2-INTERNAL" encoding and the conversion returns null. From my little bit of research, it turns out that even though this encoding is supported by the external GNU libiconv library, some glibc versions (?) don't support it with their internal iconv routines, and will instead provide the native endian encoding when "UCS-2" is specified. Nonetheless, I wonder why the native endianness is considered in the first place when Windows doesn't even run on any big endian archs (to my knowledge). And true enough, 'WIN_StringToUTF8' from core/windows/SDL_windows.h is used everywhere else in the windows backend, which is just a macro to iconv with "UTF-16LE" as source. Therefore it would IMO make sense to use this macro here as well, which would solve my problem (patch attached).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
8616
ec011c16e2fd Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents: 7852
diff changeset
     2
    SDL_windows_main.c, placed in the public domain by Sam Lantinga  4/13/98
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
    The WinMain function -- calls your program's main() function
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
*/
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     6
#include "SDL_config.h"
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     7
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     8
#ifdef __WIN32__
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
7828
1451063c8ecd Fixed building using MinGW
Sam Lantinga <slouken@libsdl.org>
parents: 7450
diff changeset
    10
/* Include this so we define UNICODE properly */
1451063c8ecd Fixed building using MinGW
Sam Lantinga <slouken@libsdl.org>
parents: 7450
diff changeset
    11
#include "../../core/windows/SDL_windows.h"
1451063c8ecd Fixed building using MinGW
Sam Lantinga <slouken@libsdl.org>
parents: 7450
diff changeset
    12
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
/* Include the SDL main definition header */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
#include "SDL.h"
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
#include "SDL_main.h"
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
#ifdef main
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
#  undef main
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
#endif /* main */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    21
static void
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    22
UnEscapeQuotes(char *arg)
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    23
{
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    24
    char *last = NULL;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    25
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    26
    while (*arg) {
6719
c250f633c040 Update VS2012 solution - add missing files; fix some static analysis warnings
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6672
diff changeset
    27
        if (*arg == '"' && (last != NULL && *last == '\\')) {
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    28
            char *c_curr = arg;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    29
            char *c_last = last;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    30
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    31
            while (*c_curr) {
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    32
                *c_last = *c_curr;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    33
                c_last = c_curr;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    34
                c_curr++;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    35
            }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    36
            *c_last = '\0';
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    37
        }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    38
        last = arg;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    39
        arg++;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    40
    }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    41
}
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    42
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
/* Parse a command line buffer into arguments */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    44
static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    45
ParseCommandLine(char *cmdline, char **argv)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    47
    char *bufp;
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    48
    char *lastp = NULL;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    49
    int argc, last_argc;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    51
    argc = last_argc = 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    52
    for (bufp = cmdline; *bufp;) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    53
        /* Skip leading whitespace */
7450
29654d59c439 Changed use of isspace() to SDL_isspace().
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7356
diff changeset
    54
        while (SDL_isspace(*bufp)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    55
            ++bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    56
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    57
        /* Skip over argument */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    58
        if (*bufp == '"') {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    59
            ++bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    60
            if (*bufp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    61
                if (argv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    62
                    argv[argc] = bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    63
                }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    64
                ++argc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    65
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    66
            /* Skip over word */
4511
ae7799d16c87 Daniel Wyatt 2010-03-26 14:52:53 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 2286
diff changeset
    67
            lastp = bufp;
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    68
            while (*bufp && (*bufp != '"' || *lastp == '\\')) {
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    69
                lastp = bufp;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    70
                ++bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    71
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    72
        } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    73
            if (*bufp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    74
                if (argv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    75
                    argv[argc] = bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    76
                }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    77
                ++argc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    78
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    79
            /* Skip over word */
7450
29654d59c439 Changed use of isspace() to SDL_isspace().
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7356
diff changeset
    80
            while (*bufp && !SDL_isspace(*bufp)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    81
                ++bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    82
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    83
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    84
        if (*bufp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    85
            if (argv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    86
                *bufp = '\0';
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    87
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    88
            ++bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    89
        }
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    90
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    91
        /* Strip out \ from \" sequences */
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    92
        if (argv && last_argc != argc) {
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    93
            UnEscapeQuotes(argv[last_argc]);
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    94
        }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    95
        last_argc = argc;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    96
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    97
    if (argv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    98
        argv[argc] = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    99
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   100
    return (argc);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
}
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
/* Pop up an out of memory message, returns to Windows */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   104
static BOOL
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   105
OutOfMemory(void)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
{
9016
648dbad92045 Remove dependency on C runtime from Windows SDLmain.
Ryan C. Gordon <icculus@icculus.org>
parents: 8616
diff changeset
   107
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal Error", "Out of memory - aborting", NULL);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   108
    return FALSE;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
}
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
6430
48d519500f7e Removed Windows CE support from SDL 2.0.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   111
#if defined(_MSC_VER)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
/* The VC++ compiler needs main defined */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
#define console_main main
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
#endif
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
/* This is where execution begins [console apps] */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   117
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   118
console_main(int argc, char *argv[])
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
{
7281
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 6719
diff changeset
   120
    SDL_SetMainReady();
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 6719
diff changeset
   121
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   122
    /* Run the application main() code */
9016
648dbad92045 Remove dependency on C runtime from Windows SDLmain.
Ryan C. Gordon <icculus@icculus.org>
parents: 8616
diff changeset
   123
    return SDL_main(argc, argv);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
}
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
/* This is where execution begins [windowed apps] */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   127
int WINAPI
6672
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   128
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   130
    char **argv;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   131
    int argc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   132
    char *cmdline;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   134
    /* Grab the command line */
6672
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   135
    TCHAR *text = GetCommandLine();
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   136
#if UNICODE
9246
a761913e5e91 Fixed bug 2786 - "UCS-2-INTERNAL" iconv encoding is not supported everywhere, use UTF-16LE instead
Sam Lantinga <slouken@libsdl.org>
parents: 9016
diff changeset
   137
    cmdline = WIN_StringToUTF8(text);
6672
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   138
#else
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   139
    cmdline = SDL_strdup(text);
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   140
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   141
    if (cmdline == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   142
        return OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   143
    }
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   145
    /* Parse it into argv and argc */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   146
    argc = ParseCommandLine(cmdline, NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   147
    argv = SDL_stack_alloc(char *, argc + 1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   148
    if (argv == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   149
        return OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   150
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   151
    ParseCommandLine(cmdline, argv);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   153
    /* Run the main program */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   154
    console_main(argc, argv);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
7356
d1a0bbe64f15 Added missing call to SDL_stack_free().
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7281
diff changeset
   156
    SDL_stack_free(argv);
d1a0bbe64f15 Added missing call to SDL_stack_free().
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7281
diff changeset
   157
6672
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   158
    SDL_free(cmdline);
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   159
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   160
    /* Hush little compiler, don't you cry... */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   161
    return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   162
}
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   164
#endif /* __WIN32__ */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   165
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   166
/* vi: set ts=4 sw=4 expandtab: */