From ef669d8c9a582104f50d96370a3e590257fa3753 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Fri, 21 Jul 2023 09:01:15 +0200 Subject: [PATCH] Core/ThreadImpl: Fix GetThreadDescription link error on older Windows --- src/Nazara/Core/Win32/ThreadImpl.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Nazara/Core/Win32/ThreadImpl.cpp b/src/Nazara/Core/Win32/ThreadImpl.cpp index 1def05650..635e9dfa9 100644 --- a/src/Nazara/Core/Win32/ThreadImpl.cpp +++ b/src/Nazara/Core/Win32/ThreadImpl.cpp @@ -12,7 +12,8 @@ namespace Nz::PlatformImpl #ifndef NAZARA_COMPILER_MINGW namespace NAZARA_ANONYMOUS_NAMESPACE { - // Windows 10, version 1607 added SetThreadDescription in order to name a thread + // Windows 10, version 1607 added GetThreadDescription and SetThreadDescription in order to name a thread + using GetThreadDescriptionFunc = HRESULT(WINAPI*)(HANDLE hThread, PWSTR* ppszThreadDescription); using SetThreadDescriptionFunc = HRESULT(WINAPI*)(HANDLE hThread, PCWSTR lpThreadDescription); #ifdef NAZARA_COMPILER_MSVC @@ -46,7 +47,12 @@ namespace Nz::PlatformImpl std::string GetThreadName(ThreadHandle threadHandle) { #ifndef NAZARA_COMPILER_MINGW + // Use GetThreadDescription if available PWSTR namePtr; + static GetThreadDescriptionFunc GetThreadDescription = reinterpret_cast(::GetProcAddress(::GetModuleHandleW(L"Kernel32.dll"), "GetThreadDescription")); + if (!GetThreadDescription) + return ""; + HRESULT hr = ::GetThreadDescription(threadHandle, &namePtr); if (FAILED(hr)) return "";