Skip to content

Commit

Permalink
Windows: Support unicode arguments for console applications (thanks, …
Browse files Browse the repository at this point in the history
…Jorgen!).

Fixes Bugzilla #2864.
  • Loading branch information
icculus committed Feb 20, 2015
1 parent 1b2cb70 commit e93ee5d
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/main/windows/SDL_windows_main.c
Expand Up @@ -109,20 +109,39 @@ OutOfMemory(void)
}

#if defined(_MSC_VER)
/* The VC++ compiler needs main defined */
#define console_main main
/* The VC++ compiler needs main/wmain defined */
# define console_utf8_main main
# if UNICODE
# define console_wmain wmain
# endif
#endif

/* This is where execution begins [console apps] */
/* This is where execution begins [console apps, ansi] */
int
console_main(int argc, char *argv[])
console_utf8_main(int argc, char *argv[])
{
SDL_SetMainReady();

/* Run the application main() code */
return SDL_main(argc, argv);
}

#if UNICODE
/* This is where execution begins [console apps, unicode] */
int
console_wmain(int argc, wchar_t *wargv[], wchar_t *wenvp)
{
char **argv = SDL_stack_alloc(char*, argc);
int i;

for (i = 0; i < argc; ++i) {
argv[i] = WIN_StringToUTF8(wargv[i]);
}

return console_utf8_main(argc, argv);
}
#endif

/* This is where execution begins [windowed apps] */
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
Expand Down Expand Up @@ -151,7 +170,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
ParseCommandLine(cmdline, argv);

/* Run the main program */
console_main(argc, argv);
console_utf8_main(argc, argv);

SDL_stack_free(argv);

Expand Down

0 comments on commit e93ee5d

Please sign in to comment.