Bug 411826 - "Mingw build error: undefined reference to `WinMain@16'" (Use CommandLineToArgvW) [p=mook.moz+mozbz@gmail.com (Mook) r=bsmedberg a1.9=schrep]
authorreed@reedloden.com
Sun, 10 Feb 2008 00:46:13 -0800
changeset 11509 9fdf49f2c81cb873b604d9bfa61a398f0bf3528a
parent 11508 eb294d94354b72636f9b59424e05cc4a1e6f3d92
child 11510 59ef9228c6e304b4b2b3e97444da10d624c34952
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs411826
milestone1.9b4pre
Bug 411826 - "Mingw build error: undefined reference to `WinMain@16'" (Use CommandLineToArgvW) [p=mook.moz+mozbz@gmail.com (Mook) r=bsmedberg a1.9=schrep]
toolkit/xre/nsWindowsWMain.cpp
--- a/toolkit/xre/nsWindowsWMain.cpp
+++ b/toolkit/xre/nsWindowsWMain.cpp
@@ -3,16 +3,40 @@
 // narrow-character strings.
 
 #ifndef XP_WIN
 #error This file only makes sense on Windows.
 #endif
 
 #include "nsUTF8Utils.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 411826 */
+
+#include <shellapi.h>
+
+int wmain(int argc, WCHAR **argv);
+
+int main(int argc, char **argv)
+{
+  LPWSTR commandLine = GetCommandLineW();
+  int argcw = 0;
+  LPWSTR *argvw = CommandLineToArgvW(commandLine, &argcw);
+  if (!argvw)
+    return 127;
+
+  int result = wmain(argcw, argvw);
+  LocalFree(argvw);
+  return result;
+}
+#endif /* __MINGW32__ */
+
 #define main NS_internal_main
 
 int main(int argc, char **argv);
 
 static char*
 AllocConvertUTF16toUTF8(const WCHAR *arg)
 {
   // be generous... UTF16 units can expand up to 3 UTF8 units
@@ -62,8 +86,9 @@ int wmain(int argc, WCHAR **argv)
     deleteUs[i] = argvConverted[i];
   int result = main(argc, argvConverted);
  
   delete[] argvConverted;
   FreeAllocStrings(argc, deleteUs);
   
   return result;
 }
+