Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed command line parsing for applications defining UNICODE
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 10, 2012
1 parent af4b382 commit 1d5e789
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/main/windows/SDL_windows_main.c
Expand Up @@ -146,22 +146,22 @@ console_main(int argc, char *argv[])

/* This is where execution begins [windowed apps] */
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmdLine, int sw)
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
{
char **argv;
int argc;
char *cmdline;
char *bufp;
size_t nLen;

/* Grab the command line */
bufp = GetCommandLine();
nLen = SDL_strlen(bufp) + 1;
cmdline = SDL_stack_alloc(char, nLen);
TCHAR *text = GetCommandLine();
#if UNICODE
cmdline = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(text), (SDL_wcslen(text)+1)*sizeof(WCHAR));
#else
cmdline = SDL_strdup(text);
#endif
if (cmdline == NULL) {
return OutOfMemory();
}
SDL_strlcpy(cmdline, bufp, nLen);

/* Parse it into argv and argc */
argc = ParseCommandLine(cmdline, NULL);
Expand All @@ -174,6 +174,8 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmdLine, int sw)
/* Run the main program */
console_main(argc, argv);

SDL_free(cmdline);

/* Hush little compiler, don't you cry... */
return 0;
}
Expand Down

0 comments on commit 1d5e789

Please sign in to comment.