Merge branch 'unicode-cmdline-args'

Handle Unicode command line arguments in console applications with compilers
other than MSVC too.

Closes #14580.
This commit is contained in:
Vadim Zeitlin
2017-03-15 00:33:40 +01:00
4 changed files with 78 additions and 30 deletions

View File

@@ -798,17 +798,31 @@ public:
// your compiler really, really wants main() to be in your main program (e.g.
// hello.cpp). Now wxIMPLEMENT_APP should add this code if required.
// For compilers that support it, prefer to use wmain() as this ensures any
// Unicode strings can be passed as command line parameters and not just those
// representable in the current locale.
#if wxUSE_UNICODE && defined(__VISUALC__)
#define wxIMPLEMENT_WXWIN_MAIN_CONSOLE \
int wmain(int argc, wchar_t **argv) \
{ \
wxDISABLE_DEBUG_SUPPORT(); \
// For compilers that support it, prefer to use wmain() and let the CRT parse
// the command line for us, for the others parse it ourselves under Windows to
// ensure that wxWidgets console applications accept arbitrary Unicode strings
// as command line parameters and not just those representable in the current
// locale (under Unix UTF-8, capable of representing any Unicode string, is
// almost always used and there is no way to retrieve the Unicode command line
// anyhow).
#if wxUSE_UNICODE && defined(__WINDOWS__)
#ifdef __VISUALC__
#define wxIMPLEMENT_WXWIN_MAIN_CONSOLE \
int wmain(int argc, wchar_t **argv) \
{ \
wxDISABLE_DEBUG_SUPPORT(); \
\
return wxEntry(argc, argv); \
}
return wxEntry(argc, argv); \
}
#else // No wmain(), use main() but don't trust its arguments.
#define wxIMPLEMENT_WXWIN_MAIN_CONSOLE \
int main(int, char **) \
{ \
wxDISABLE_DEBUG_SUPPORT(); \
\
return wxEntry(); \
}
#endif
#else // Use standard main()
#define wxIMPLEMENT_WXWIN_MAIN_CONSOLE \
int main(int argc, char **argv) \

View File

@@ -54,7 +54,7 @@ extern int WXDLLIMPEXP_BASE wxEntry(int& argc, char **argv);
// Under Windows we define additional wxEntry() overloads with signature
// compatible with WinMain() and not the traditional main().
#if wxUSE_GUI && defined(__WINDOWS__)
#ifdef __WINDOWS__
#include "wx/msw/init.h"
#endif

View File

@@ -15,6 +15,14 @@
// Windows-specific wxEntry() overload and wxIMPLEMENT_WXWIN_MAIN definition
// ----------------------------------------------------------------------------
// wxEntry() overload using the command line for the current process, instead
// of argc/argv provided by the CRT. This is only really useful when using
// Unicode with a compiler not providing wmain() or similar entry point, but is
// always provided for consistency.
extern int WXDLLIMPEXP_BASE wxEntry();
#if wxUSE_GUI
// we need HINSTANCE declaration to define WinMain()
#include "wx/msw/wrapwin.h"
@@ -81,5 +89,6 @@ extern WXDLLIMPEXP_CORE int
} \
wxIMPLEMENT_WXWIN_MAIN_BORLAND_NONSTANDARD
#endif // wxUSE_GUI
#endif // _WX_MSW_INIT_H_