From cc7ee0bc72ccd0ff51963132848aee3cddae8602 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 4 Sep 2012 23:06:45 +0300 Subject: [PATCH] Convert command line arguments on Windows from UTF-16 to UTF-8 --- source/core/main.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/source/core/main.cpp b/source/core/main.cpp index 19791ee..dc8122d 100644 --- a/source/core/main.cpp +++ b/source/core/main.cpp @@ -1,14 +1,40 @@ #ifdef WIN32 #include +#include +#include #endif #include "application.h" #ifdef WIN32 +using namespace std; +using namespace Msp; + int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/) { int argc = 0; - LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc); - return Msp::Application::run(argc, (char **)argv, hInstance); + LPWSTR *argv_w = CommandLineToArgvW(GetCommandLineW(), &argc); + + unsigned max_size = 0; + for(int i=0; i(argv_buf); + char *argv_ptr = argv_buf+(argc+1)*sizeof(char *); + for(int i=0; i(argv_w[i]), wcslen(argv_w[i])*2); + arg = StringCodec::transcode(arg); + copy(arg.begin(), arg.end(), argv_ptr); + argv_ptr += arg.size(); + *argv_ptr++ = 0; + } + + LocalFree(argv_w); + int exit_code = Msp::Application::run(argc, argv, hInstance); + delete[] argv_buf; + return exit_code; } #endif -- 2.45.2