Windows CE patch for incorrect argv[0] handling

In the win32 version of SDL_main.c the following code appears:

#ifdef _WIN32_WCE
nLen = wcslen(szCmdLine)+128+1;
bufp = (wchar_t )alloca(nLen2);
GetModuleFileName(NULL, bufp, 128);
wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp));
nLen = wcslen(bufp)+1;
cmdline = (char *)alloca(nLen);
if ( cmdline == NULL ) {
return OutOfMemory();
}
WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
#else

It copies the executable name to the command line, appends the rest of the
command line and then parses it.
However if the executable name contains spaces (such as in the case of
\Windows\Start Menu\Testapp.exe), it has to be surrounded by quotes.

The code below fixes the problem:

#ifdef _WIN32_WCE
nLen = wcslen(szCmdLine)+128+1;
bufp = (wchar_t )alloca(nLen2);
bufp[0] = ‘"’;
GetModuleFileName(NULL, bufp+1, 128-3);
wcscpy (bufp+wcslen(bufp), “” ");
wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp));
nLen = wcslen(bufp)+1;
cmdline = (char *)alloca(nLen);
if ( cmdline == NULL ) {
return OutOfMemory();
}
WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
#else

It copies the executable name to the command line, appends the rest of the
command line and then parses it.
However if the executable name contains spaces (such as in the case of
\Windows\Start Menu\Testapp.exe), it has to be surrounded by quotes.

The code below fixes the problem:

[snipped]

Thanks! I’ve added your fix to CVS.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment