From 4eb0bd7d98d34651360ea1b9f5689889f1b3e72d Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 11 Dec 2024 20:23:11 -0500 Subject: [PATCH] Cast ::GetLastError to int (flutter/engine#57113) `GetLastError` returns an unsigned 32 bit integer that was being implicitly cast to an int for the std::variant<..., int>. This was causing my build to fail with: ``` ../../flutter/shell/platform/windows/platform_handler.cc(178,12): error: no viable conversion from returned value of type 'DWORD' (aka 'unsigned long') to function return type 'std::variant' (aka 'variant, allocator>, int>') 178 | return ::GetLastError(); | ^~~~~~~~~~~~~~~~ ../../../../../../../Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.42.34433/include\variant(923,7): note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'DWORD' (aka 'unsigned long') to 'const variant, int> &' for 1st argument 923 | class variant : private _SMF_control<_Variant_destroy_layer<_Types...>, _Types...> { // discriminated union | ^~~~~~~ ``` Commands: ``` ./flutter/tools/gn --runtime-mode release --no-rbe ninja -C .\out\host_release windows gen_snapshot flutter/build/archives:windows_flutter ``` Explicitly casting `::GetLastError` to an int fixes this issue. I'm running on Windows 11 (Version 10.0.26100 Build 26100) with VS 2022 Community Edition. @loic-sharma Co-authored-by: Eric Seidel --- .../flutter/shell/platform/windows/platform_handler.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/shell/platform/windows/platform_handler.cc b/engine/src/flutter/shell/platform/windows/platform_handler.cc index 197de59345..48ebf0cf04 100644 --- a/engine/src/flutter/shell/platform/windows/platform_handler.cc +++ b/engine/src/flutter/shell/platform/windows/platform_handler.cc @@ -60,7 +60,7 @@ class ScopedGlobalMemory { memory_ = ::GlobalAlloc(flags, bytes); if (!memory_) { FML_LOG(ERROR) << "Unable to allocate global memory: " - << ::GetLastError(); + << static_cast(::GetLastError()); } } @@ -68,7 +68,7 @@ class ScopedGlobalMemory { if (memory_) { if (::GlobalFree(memory_) != nullptr) { FML_LOG(ERROR) << "Failed to free global allocation: " - << ::GetLastError(); + << static_cast(::GetLastError()); } } } @@ -175,12 +175,12 @@ std::variant ScopedClipboard::GetString() { HANDLE data = ::GetClipboardData(CF_UNICODETEXT); if (data == nullptr) { - return ::GetLastError(); + return static_cast(::GetLastError()); } ScopedGlobalLock locked_data(data); if (!locked_data.get()) { - return ::GetLastError(); + return static_cast(::GetLastError()); } return static_cast(locked_data.get()); }