Flutter Engine
The Flutter Engine
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
5#include "flutter/fml/command_line.h"
6
7#include <windows.h>
8
9#include <Shellapi.h>
10#include <memory>
11
12namespace fml {
13
14std::optional<CommandLine> CommandLineFromPlatform() {
15 wchar_t* command_line = GetCommandLineW();
16 int unicode_argc;
17 std::unique_ptr<wchar_t*[], decltype(::LocalFree)*> unicode_argv(
18 CommandLineToArgvW(command_line, &unicode_argc), ::LocalFree);
19 if (!unicode_argv) {
20 return std::nullopt;
21 }
22 std::vector<std::string> utf8_argv;
23 for (int i = 0; i < unicode_argc; ++i) {
24 wchar_t* arg = unicode_argv[i];
25 int arg_len = WideCharToMultiByte(CP_UTF8, 0, arg, wcslen(arg), nullptr, 0,
26 nullptr, nullptr);
27 std::string utf8_arg(arg_len, 0);
28 WideCharToMultiByte(CP_UTF8, 0, arg, -1, utf8_arg.data(), utf8_arg.size(),
29 nullptr, nullptr);
30 utf8_argv.push_back(std::move(utf8_arg));
31 }
32 return CommandLineFromIterators(utf8_argv.begin(), utf8_argv.end());
33}
34
35} // namespace fml
std::optional< CommandLine > CommandLineFromPlatform()
CommandLine CommandLineFromIterators(InputIterator first, InputIterator last)