Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
errors_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/platform/win/errors_win.h"
6
7#include <Windows.h>
8
9#include <sstream>
10
11#include "flutter/fml/platform/win/wstring_conversion.h"
12
13namespace fml {
14
15std::string GetLastErrorMessage() {
16 DWORD last_error = ::GetLastError();
17 if (last_error == 0) {
18 return {};
19 }
20
21 const DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
22 FORMAT_MESSAGE_FROM_SYSTEM |
23 FORMAT_MESSAGE_IGNORE_INSERTS;
24
25 wchar_t* buffer = nullptr;
26 size_t size = ::FormatMessage(
27 flags, // dwFlags
28 NULL, // lpSource
29 last_error, // dwMessageId
30 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // dwLanguageId
31 (LPWSTR)&buffer, // lpBuffer
32 0, // nSize
33 NULL // Arguments
34 );
35
36 std::wstring message(buffer, size);
37
38 ::LocalFree(buffer);
39
40 std::wstringstream stream;
41 stream << message << " (" << last_error << ").";
42
43 return WideStringToUtf8(stream.str());
44}
45
46} // namespace fml
FlutterSemanticsFlag flags
static const uint8_t buffer[]
Win32Message message
constexpr std::size_t size(T(&array)[N])
Definition size.h:13
std::string GetLastErrorMessage()
Definition errors_win.cc:15
std::string WideStringToUtf8(const std::wstring_view str)
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)
unsigned long DWORD