Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
command_line_win.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <windows.h>
8
9#include <Shellapi.h>
10#include <memory>
11
12namespace fml {
13
14CommandLine CommandLineFromWideArgv(int argc, const wchar_t* const* argv) {
15 std::vector<std::string> utf8_argv;
16 for (int i = 0; i < argc; ++i) {
17 const wchar_t* arg = argv[i];
18 int arg_len = WideCharToMultiByte(CP_UTF8, 0, arg, wcslen(arg), nullptr, 0,
19 nullptr, nullptr);
20 std::string utf8_arg(arg_len, 0);
21 WideCharToMultiByte(CP_UTF8, 0, arg, wcslen(arg), utf8_arg.data(),
22 utf8_arg.size(), nullptr, nullptr);
23 utf8_argv.push_back(std::move(utf8_arg));
24 }
25 return CommandLineFromIterators(utf8_argv.begin(), utf8_argv.end());
26}
27
28std::optional<CommandLine> CommandLineFromPlatform() {
29 wchar_t* command_line = GetCommandLineW();
30 int unicode_argc;
31 std::unique_ptr<wchar_t*[], decltype(::LocalFree)*> unicode_argv(
32 CommandLineToArgvW(command_line, &unicode_argc), ::LocalFree);
33 if (!unicode_argv) {
34 return std::nullopt;
35 }
36 return CommandLineFromWideArgv(unicode_argc, unicode_argv.get());
37}
38
39} // namespace fml
char ** argv
Definition library.h:9
CommandLine CommandLineFromWideArgv(int argc, const wchar_t *const *argv)
std::optional< CommandLine > CommandLineFromPlatform()
CommandLine CommandLineFromIterators(InputIterator first, InputIterator last)