From c9a458bfe87445dd4042b50522d9e0fed1c2f694 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 11 Mar 2017 01:44:07 +0100 Subject: [PATCH] Use Win32 ::CommandLineToArgvW() to tokenize command line Use the standard function in Unicode build instead of our own emulation, it should give better results and is marginally more efficient as it does fewer heap allocations than our own wxCmdLineParser::ConvertStringToArgs(). --- src/msw/main.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/msw/main.cpp b/src/msw/main.cpp index f2ea2860b7..798c3d5457 100644 --- a/src/msw/main.cpp +++ b/src/msw/main.cpp @@ -29,7 +29,10 @@ #include "wx/utils.h" #endif //WX_PRECOMP -#include "wx/cmdline.h" +// wxCmdLineParser is only used when we can't use ::CommandLineToArgvW(). +#if !wxUSE_UNICODE + #include "wx/cmdline.h" +#endif #include "wx/dynlib.h" #include "wx/msw/private.h" @@ -203,6 +206,22 @@ struct wxMSWCommandLineArguments wxMSWCommandLineArguments() { argc = 0; argv = NULL; } // Initialize this object from the current process command line. + // + // In Unicode build prefer to use the standard function for tokenizing the + // command line, but we can't use it with narrow strings, so use our own + // approximation instead then. +#if wxUSE_UNICODE + void Init() + { + argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + } + + ~wxMSWCommandLineArguments() + { + if ( argc ) + ::LocalFree(argv); + } +#else // !wxUSE_UNICODE void Init() { // Get the command line. @@ -239,6 +258,7 @@ struct wxMSWCommandLineArguments wxDELETEA(argv); argc = 0; } +#endif // wxUSE_UNICODE/!wxUSE_UNICODE int argc; wxChar **argv;