1 // This file is a .cpp file meant to be included in nsBrowserApp.cpp and other
2 // similar bootstrap code. It converts wide-character windows wmain into UTF-8
3 // narrow-character strings.
6 #error This file only makes sense on Windows.
9 #include "nsUTF8Utils.h"
13 /* MingW currently does not implement a wide version of the
14 startup routines. Workaround is to implement something like
15 it ourselves. See bug 411826 */
19 int wmain(int argc
, WCHAR
**argv
);
21 int main(int argc
, char **argv
)
23 LPWSTR commandLine
= GetCommandLineW();
25 LPWSTR
*argvw
= CommandLineToArgvW(commandLine
, &argcw
);
29 int result
= wmain(argcw
, argvw
);
33 #endif /* __MINGW32__ */
35 #define main NS_internal_main
37 int main(int argc
, char **argv
);
40 AllocConvertUTF16toUTF8(const WCHAR
*arg
)
42 // be generous... UTF16 units can expand up to 3 UTF8 units
43 int len
= wcslen(arg
);
44 char *s
= new char[len
* 3 + 1];
48 ConvertUTF16toUTF8
convert(s
);
49 convert
.write(arg
, len
);
50 convert
.write_terminator();
55 FreeAllocStrings(int argc
, char **argv
)
65 int wmain(int argc
, WCHAR
**argv
)
67 char **argvConverted
= new char*[argc
+ 1];
71 for (int i
= 0; i
< argc
; ++i
) {
72 argvConverted
[i
] = AllocConvertUTF16toUTF8(argv
[i
]);
73 if (!argvConverted
[i
]) {
77 argvConverted
[argc
] = NULL
;
79 // need to save argvConverted copy for later deletion.
80 char **deleteUs
= new char*[argc
+1];
82 FreeAllocStrings(argc
, argvConverted
);
85 for (int i
=0; i
<argc
; i
++)
86 deleteUs
[i
] = argvConverted
[i
];
87 int result
= main(argc
, argvConverted
);
89 delete[] argvConverted
;
90 FreeAllocStrings(argc
, deleteUs
);