Fixed command line parsing for applications defining UNICODE
authorSam Lantinga <slouken@libsdl.org>
Sat, 10 Nov 2012 10:37:38 -0800
changeset 6672 b61791cd595a
parent 6671 394e25751ef5
child 6673 78f18a929123
child 8340 e470405f3ae9
Fixed command line parsing for applications defining UNICODE
src/main/windows/SDL_windows_main.c
--- a/src/main/windows/SDL_windows_main.c	Fri Nov 09 08:48:23 2012 -0800
+++ b/src/main/windows/SDL_windows_main.c	Sat Nov 10 10:37:38 2012 -0800
@@ -146,22 +146,22 @@
 
 /* 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);
@@ -174,6 +174,8 @@
     /* Run the main program */
     console_main(argc, argv);
 
+    SDL_free(cmdline);
+
     /* Hush little compiler, don't you cry... */
     return 0;
 }