Skip to content

Commit

Permalink
Bug 472063 - mingw build failure: undefined reference to 'WinMain@16'…
Browse files Browse the repository at this point in the history
… in windbgdlg.cpp, r=neil, sr=bsmedberg
  • Loading branch information
Mook committed Jan 13, 2009
1 parent 19c04f4 commit 93ede4e
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions xpcom/windbgdlg/windbgdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,65 @@
#include <windows.h>
#include <stdlib.h>

#ifdef __MINGW32__

/* MingW currently does not implement a wide version of the
startup routines. Workaround is to implement something like
it ourselves. See bug 472063 */

#include <shellapi.h>

int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);

#undef __argc
#undef __wargv

static int __argc;
static wchar_t** __wargv;

int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCommandLine, int nCmdShow)
{
LPWSTR commandLine = GetCommandLineW();

/* parse for __argc and __wargv for compatibility, since mingw
* doesn't claim to support it :(
*/
__wargv = CommandLineToArgvW(commandLine, &__argc);
if (!__wargv)
return 127;

/* need to strip off any leading whitespace plus the first argument
* (the executable itself) to match what should be passed to wWinMain
*/
while ((*commandLine <= L' ') && *commandLine) {
++commandLine;
}
if (*commandLine == L'"') {
++commandLine;
while ((*commandLine != L'"') && *commandLine) {
++commandLine;
}
if (*commandLine) {
++commandLine;
}
} else {
while (*commandLine > L' ') {
++commandLine;
}
}
while ((*commandLine <= L' ') && *commandLine) {
++commandLine;
}

int result = wWinMain(hInstance, hPrevInstance, commandLine, nCmdShow);
LocalFree(__wargv);
return result;
}
#endif /* __MINGW32__ */


int WINAPI
wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpszCmdLine, int nCmdShow)
Expand Down

0 comments on commit 93ede4e

Please sign in to comment.