| 256 | } |
| 257 | |
| 258 | std::vector<std::string> getCmdLineVector(int, const char**) |
| 259 | { |
| 260 | // Discard the input as it will either be ASCII or not available |
| 261 | |
| 262 | // We need to get the Wide command line and convert it to utf8 command line parameters |
| 263 | const auto cmdline = GetCommandLineW(); |
| 264 | |
| 265 | int argc{}; |
| 266 | auto* argw = CommandLineToArgvW(cmdline, &argc); |
| 267 | if (argw == nullptr) |
| 268 | { |
| 269 | std::cerr << "CommandLineToArgvW failed to convert commandline"; |
| 270 | // We will continue but just ignore the command line args. |
| 271 | argc = 0; |
| 272 | } |
| 273 | |
| 274 | // This will hold a utf8 string of the command line |
| 275 | std::vector<std::string> argvStrs; |
| 276 | argvStrs.resize(argc); |
| 277 | |
| 278 | for (auto i = 0; i < argc; ++i) |
| 279 | { |
| 280 | int length = WideCharToMultiByte(CP_UTF8, 0, argw[i], -1, nullptr, 0, nullptr, nullptr); |
| 281 | |
| 282 | if (length == 0) |
| 283 | { |
| 284 | // Sadly can't print what the argument is that is causing the issue as it needs to be in utf8... |
| 285 | std::cerr << "Failed to get cmdline argument utf8 length."; |
| 286 | continue; |
| 287 | } |
| 288 | // When resizing a std::string the null termination is handled implicitly. i.e. resize to true length not null terminated length. |
| 289 | argvStrs[i].resize(length - 1); |
| 290 | |
| 291 | if (WideCharToMultiByte(CP_UTF8, 0, argw[i], -1, argvStrs[i].data(), length, nullptr, nullptr) == 0) |
| 292 | { |
| 293 | std::cerr << "Failed to convert cmdline argument to utf8."; |
| 294 | } |
| 295 | } |
| 296 | LocalFree(reinterpret_cast<HLOCAL>(argw)); |
| 297 | return argvStrs; |
| 298 | } |
| 299 | |
| 300 | // 0x00407FFD |
| 301 | bool lockSingleInstance() |