Use GetCommandLineW() to get a UTF16-encoded command line on Windows (#2248).
[dcpomatic.git] / src / lib / cross_windows.cc
index 0549615787214dbd0ce4ef18b31ced6b5df78aca..200b724854731b2582110f752d45abf87921831b 100644 (file)
@@ -44,10 +44,11 @@ extern "C" {
 #include <setupapi.h>
 #include <fileapi.h>
 #undef DATADIR
-#include <shlwapi.h>
-#include <shlobj.h>
-#include <shellapi.h>
 #include <knownfolders.h>
+#include <processenv.h>
+#include <shellapi.h>
+#include <shlobj.h>
+#include <shlwapi.h>
 #include <fcntl.h>
 #include <fstream>
 #include <map>
@@ -657,3 +658,17 @@ show_in_file_manager (boost::filesystem::path, boost::filesystem::path select)
        return (reinterpret_cast<int64_t>(r) <= 32);
 }
 
+
+ArgFixer::ArgFixer(int, char**)
+{
+       auto cmd_line = GetCommandLineW();
+       auto wide_argv = CommandLineToArgvW(cmd_line, &_argc);
+
+       _argv_strings.resize(_argc);
+       _argv = new char*[_argc];
+       for (int i = 0; i < _argc; ++i) {
+               _argv_strings[i] = wchar_to_utf8(wide_argv[i]);
+               _argv[i] = const_cast<char*>(_argv_strings[i].c_str());
+       }
+}
+