annotate src/main/win32/SDL_win32_main.c @ 4919:716b2cbf4c9e

First pass at Windows multi-touch gesture support
author Sam Lantinga <slouken@libsdl.org>
date Tue, 30 Nov 2010 17:58:51 -0800
parents ae7799d16c87
children
rev   line source
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL_main.c, placed in the public domain by Sam Lantinga 4/13/98
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 */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 #include <stdio.h>
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 #include <stdlib.h>
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
1433
bb6839704ed6 SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents: 1423
diff changeset
10 #define WIN32_LEAN_AND_MEAN
bb6839704ed6 SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents: 1423
diff changeset
11 #include <windows.h>
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1286
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 # ifndef _WIN32_WCE_EMULATION
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 # undef main
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 # endif /* _WIN32_WCE_EMULATION */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 #endif /* main */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 #if defined(_WIN32_WCE) && _WIN32_WCE < 300
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 /* seems to be undefined in Win CE although in online help */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #endif /* _WIN32_WCE < 300 */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
28 static void
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
29 UnEscapeQuotes(char *arg)
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 char *last = NULL;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
32
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
33 while (*arg) {
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
34 if (*arg == '"' && *last == '\\') {
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
35 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
36 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
37
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
38 while (*c_curr) {
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
39 *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
40 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
41 c_curr++;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
42 }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
43 *c_last = '\0';
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
44 }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
45 last = arg;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
46 arg++;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
47 }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
48 }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
49
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 /* 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
51 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
52 ParseCommandLine(char *cmdline, char **argv)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 {
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
54 char *bufp;
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
55 char *lastp = NULL;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
56 int argc, last_argc;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
58 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
59 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
60 /* Skip leading whitespace */
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 while (isspace(*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
62 ++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 /* 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
65 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
66 ++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
67 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
68 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
69 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
70 }
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 ++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
72 }
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 /* Skip over word */
4511
ae7799d16c87 Daniel Wyatt 2010-03-26 14:52:53 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 2286
diff changeset
74 lastp = bufp;
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
75 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
76 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
77 ++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
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 } 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
80 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
81 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
82 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
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 ++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
85 }
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 /* Skip over word */
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 while (*bufp && !isspace(*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
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 }
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
90 }
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
91 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
92 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
93 *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
94 }
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
95 ++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
96 }
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
97
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
98 /* 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
99 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
100 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
101 }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
102 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
103 }
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 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
105 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
106 }
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
107 return (argc);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 }
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 /* Show an error message */
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
111 static void
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
112 ShowError(const char *title, const char *message)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 {
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 /* If USE_MESSAGEBOX is defined, you need to link with user32.lib */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 #ifdef USE_MESSAGEBOX
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
116 MessageBox(NULL, message, title, MB_ICONEXCLAMATION | MB_OK);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 #else
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
118 fprintf(stderr, "%s: %s\n", title, message);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 #endif
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 }
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 /* 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
123 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
124 OutOfMemory(void)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 {
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
126 ShowError("Fatal Error", "Out of memory - aborting");
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 return FALSE;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 }
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 #if defined(_MSC_VER) && !defined(_WIN32_WCE)
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 /* The VC++ compiler needs main defined */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 #define console_main main
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 #endif
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 /* 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
136 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
137 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
138 {
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
139 int status;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140
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 /* Run the application main() code */
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 status = SDL_main(argc, argv);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143
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
144 /* Exit cleanly, calling atexit() functions */
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 exit(status);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146
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
147 /* 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
148 return 0;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 }
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 /* 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
152 int WINAPI
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 WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmdLine, int sw)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 {
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
155 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
156 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
157 char *cmdline;
1286
d7bca8c8161e Use the executable directory, not the current directory, for stdio output files
Sam Lantinga <slouken@libsdl.org>
parents: 766
diff changeset
158 #ifdef _WIN32_WCE
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
159 wchar_t *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
160 int nLen;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 #else
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
162 char *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
163 size_t nLen;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 #endif
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
166 #ifdef _WIN32_WCE
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
167 nLen = wcslen(szCmdLine) + 128 + 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
168 bufp = SDL_stack_alloc(wchar_t, nLen * 2);
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
169 wcscpy(bufp, TEXT("\""));
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
170 GetModuleFileName(NULL, bufp + 1, 128 - 3);
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
171 wcscpy(bufp + wcslen(bufp), TEXT("\" "));
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
172 wcsncpy(bufp + wcslen(bufp), szCmdLine, nLen - wcslen(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
173 nLen = wcslen(bufp) + 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
174 cmdline = SDL_stack_alloc(char, nLen);
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
175 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
176 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
177 }
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
178 WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 #else
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
180 /* Grab the command line */
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
181 bufp = GetCommandLine();
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
182 nLen = SDL_strlen(bufp) + 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
183 cmdline = SDL_stack_alloc(char, nLen);
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
184 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
185 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
186 }
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
187 SDL_strlcpy(cmdline, bufp, nLen);
1465
8dfa9a6d69a5 Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
188 #endif
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189
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
190 /* 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
191 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
192 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
193 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
194 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
195 }
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
196 ParseCommandLine(cmdline, argv);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197
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
198 /* 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
199 console_main(argc, argv);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200
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
201 /* 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
202 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
203 }
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204
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
205 /* vi: set ts=4 sw=4 expandtab: */