src/main/windows/SDL_windows_main.c
changeset 6672 b61791cd595a
parent 6430 48d519500f7e
child 6719 c250f633c040
equal deleted inserted replaced
6671:394e25751ef5 6672:b61791cd595a
   144     return 0;
   144     return 0;
   145 }
   145 }
   146 
   146 
   147 /* This is where execution begins [windowed apps] */
   147 /* This is where execution begins [windowed apps] */
   148 int WINAPI
   148 int WINAPI
   149 WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmdLine, int sw)
   149 WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
   150 {
   150 {
   151     char **argv;
   151     char **argv;
   152     int argc;
   152     int argc;
   153     char *cmdline;
   153     char *cmdline;
   154     char *bufp;
       
   155     size_t nLen;
       
   156 
   154 
   157     /* Grab the command line */
   155     /* Grab the command line */
   158     bufp = GetCommandLine();
   156     TCHAR *text = GetCommandLine();
   159     nLen = SDL_strlen(bufp) + 1;
   157 #if UNICODE
   160     cmdline = SDL_stack_alloc(char, nLen);
   158     cmdline = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(text), (SDL_wcslen(text)+1)*sizeof(WCHAR));
       
   159 #else
       
   160     cmdline = SDL_strdup(text);
       
   161 #endif
   161     if (cmdline == NULL) {
   162     if (cmdline == NULL) {
   162         return OutOfMemory();
   163         return OutOfMemory();
   163     }
   164     }
   164     SDL_strlcpy(cmdline, bufp, nLen);
       
   165 
   165 
   166     /* Parse it into argv and argc */
   166     /* Parse it into argv and argc */
   167     argc = ParseCommandLine(cmdline, NULL);
   167     argc = ParseCommandLine(cmdline, NULL);
   168     argv = SDL_stack_alloc(char *, argc + 1);
   168     argv = SDL_stack_alloc(char *, argc + 1);
   169     if (argv == NULL) {
   169     if (argv == NULL) {
   172     ParseCommandLine(cmdline, argv);
   172     ParseCommandLine(cmdline, argv);
   173 
   173 
   174     /* Run the main program */
   174     /* Run the main program */
   175     console_main(argc, argv);
   175     console_main(argc, argv);
   176 
   176 
       
   177     SDL_free(cmdline);
       
   178 
   177     /* Hush little compiler, don't you cry... */
   179     /* Hush little compiler, don't you cry... */
   178     return 0;
   180     return 0;
   179 }
   181 }
   180 
   182 
   181 #endif /* __WIN32__ */
   183 #endif /* __WIN32__ */