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().
This commit is contained in:
Vadim Zeitlin 2017-03-11 01:44:07 +01:00
parent 5b74044c3e
commit c9a458bfe8

View File

@ -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;