Bug 472063 - mingw build failure: undefined reference to 'WinMain@16' in windbgdlg.cpp, r=neil, sr=bsmedberg
authorMook <mook.moz+mozbz@gmail.com>
Mon, 12 Jan 2009 21:43:35 -0800
changeset 23577 cfcb51bdb85201f86cbf94cca5c87151499ddecc
parent 23576 2bed74c80db848d374d81143721aebbbb029e67d
child 23578 5eeab4033c20a1031e84d532a62bb3caa97290dc
push id4618
push userphilringnalda@gmail.com
push dateTue, 13 Jan 2009 05:44:12 +0000
treeherdermozilla-central@cfcb51bdb852 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil, bsmedberg
bugs472063
milestone1.9.2a1pre
Bug 472063 - mingw build failure: undefined reference to 'WinMain@16' in windbgdlg.cpp, r=neil, sr=bsmedberg
xpcom/windbgdlg/windbgdlg.cpp
--- a/xpcom/windbgdlg/windbgdlg.cpp
+++ b/xpcom/windbgdlg/windbgdlg.cpp
@@ -38,16 +38,75 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* Windows only app to show a modal debug dialog - launched by nsDebug.cpp */
 
 #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)
 {
     /* support for auto answering based on words in the assertion.
      * the assertion message is sent as a series of arguements (words) to the commandline.
      * set a "word" to 0xffffffff to let the word not affect this code.
      * set a "word" to 0xfffffffe to show the dialog.