From e7ddfb04304433bb2b0c94861b653ee92f859292 Mon Sep 17 00:00:00 2001 From: Ryan Butler Date: Tue, 1 Sep 2026 08:38:42 -0500 Subject: [PATCH] fix(core): declare SetThreadDescription/GetThreadDescription for MinGW MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mingw-w64 header snapshot bundled with Qt's mingw1310_64 toolchain does not declare SetThreadDescription or GetThreadDescription in , even though kernel32.dll exports both (Windows 10 1607+) and MSVC's Windows SDK already declares them. Widening _WIN32_WINNT/WINVER does not help — the prototypes are absent outright, confirmed with an isolated repro against this toolchain. Introduced by bc345850 (#5246, System Info dialog Threads/Logs tabs), which added the first calls to these APIs in this codebase. It builds cleanly under MSVC because that SDK already has the declarations, so a MinGW build is the only way to catch this. Declare both functions manually, dllimport from kernel32 (already linked in all three files), guarded to __MINGW32__ so MSVC and non-Windows builds are untouched. Verified the declared signatures against the real Windows SDK header actually shipped on this machine. --- src/core/AsyncLogWriter.cpp | 7 +++++++ src/core/SystemInfo.cpp | 7 +++++++ src/core/ThreadName.cpp | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/src/core/AsyncLogWriter.cpp b/src/core/AsyncLogWriter.cpp index 95da47acb..a005ec3e6 100644 --- a/src/core/AsyncLogWriter.cpp +++ b/src/core/AsyncLogWriter.cpp @@ -22,6 +22,13 @@ #define NOMINMAX #endif #include +#if defined(__MINGW32__) +// This mingw-w64 header snapshot doesn't declare SetThreadDescription even +// though kernel32.dll exports it (Windows 10 1607+, MSVC's SDK already has +// it). Widening _WIN32_WINNT doesn't help — the prototype is absent outright. +extern "C" __declspec(dllimport) HRESULT WINAPI + SetThreadDescription(HANDLE hThread, PCWSTR lpThreadDescription); +#endif #elif defined(__APPLE__) #include #elif defined(__linux__) diff --git a/src/core/SystemInfo.cpp b/src/core/SystemInfo.cpp index d4cf6069a..db7252d8b 100644 --- a/src/core/SystemInfo.cpp +++ b/src/core/SystemInfo.cpp @@ -15,6 +15,13 @@ #endif #include #include +#if defined(__MINGW32__) +// This mingw-w64 header snapshot doesn't declare GetThreadDescription even +// though kernel32.dll exports it (Windows 10 1607+, MSVC's SDK already has +// it). Widening _WIN32_WINNT doesn't help — the prototype is absent outright. +extern "C" __declspec(dllimport) HRESULT WINAPI + GetThreadDescription(HANDLE hThread, PWSTR* ppszThreadDescription); +#endif #elif defined(Q_OS_MAC) #include #include diff --git a/src/core/ThreadName.cpp b/src/core/ThreadName.cpp index acb5666a4..866432563 100644 --- a/src/core/ThreadName.cpp +++ b/src/core/ThreadName.cpp @@ -8,6 +8,13 @@ #endif #include #include +#if defined(__MINGW32__) +// This mingw-w64 header snapshot doesn't declare SetThreadDescription even +// though kernel32.dll exports it (Windows 10 1607+, MSVC's SDK already has +// it). Widening _WIN32_WINNT doesn't help — the prototype is absent outright. +extern "C" __declspec(dllimport) HRESULT WINAPI + SetThreadDescription(HANDLE hThread, PCWSTR lpThreadDescription); +#endif #elif defined(__APPLE__) #include #elif defined(__linux__)