Core/ThreadImpl: Fix GetThreadDescription link error on older Windows
This commit is contained in:
@@ -12,7 +12,8 @@ namespace Nz::PlatformImpl
|
|||||||
#ifndef NAZARA_COMPILER_MINGW
|
#ifndef NAZARA_COMPILER_MINGW
|
||||||
namespace NAZARA_ANONYMOUS_NAMESPACE
|
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);
|
using SetThreadDescriptionFunc = HRESULT(WINAPI*)(HANDLE hThread, PCWSTR lpThreadDescription);
|
||||||
|
|
||||||
#ifdef NAZARA_COMPILER_MSVC
|
#ifdef NAZARA_COMPILER_MSVC
|
||||||
@@ -46,7 +47,12 @@ namespace Nz::PlatformImpl
|
|||||||
std::string GetThreadName(ThreadHandle threadHandle)
|
std::string GetThreadName(ThreadHandle threadHandle)
|
||||||
{
|
{
|
||||||
#ifndef NAZARA_COMPILER_MINGW
|
#ifndef NAZARA_COMPILER_MINGW
|
||||||
|
// Use GetThreadDescription if available
|
||||||
PWSTR namePtr;
|
PWSTR namePtr;
|
||||||
|
static GetThreadDescriptionFunc GetThreadDescription = reinterpret_cast<GetThreadDescriptionFunc>(::GetProcAddress(::GetModuleHandleW(L"Kernel32.dll"), "GetThreadDescription"));
|
||||||
|
if (!GetThreadDescription)
|
||||||
|
return "<GetThreadDescription not supported>";
|
||||||
|
|
||||||
HRESULT hr = ::GetThreadDescription(threadHandle, &namePtr);
|
HRESULT hr = ::GetThreadDescription(threadHandle, &namePtr);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
return "<GetThreadDescription failed: " + std::to_string(HRESULT_CODE(hr)) + ">";
|
return "<GetThreadDescription failed: " + std::to_string(HRESULT_CODE(hr)) + ">";
|
||||||
|
|||||||
Reference in New Issue
Block a user