mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-17 08:55:48 +00:00
Use GetModuleHandle() for kernel32.dll, since it's guaranteed to be loaded already
This commit is contained in:
parent
4723f8ba7c
commit
46cea5011d
@ -33,12 +33,10 @@ typedef struct tagTHREADNAME_INFO
|
||||
typedef HRESULT (WINAPI *SetThreadDescription_t)(HANDLE, PCWSTR);
|
||||
|
||||
void setThreadNameWin32(const char* name) {
|
||||
HMODULE hKernel32;
|
||||
SetThreadDescription_t setThreadDescriptionFunc;
|
||||
|
||||
// This function is only supported on Windows 10 RS1 and later
|
||||
hKernel32 = LoadLibraryA("kernel32.dll");
|
||||
setThreadDescriptionFunc = (SetThreadDescription_t)GetProcAddress(hKernel32, "SetThreadDescription");
|
||||
setThreadDescriptionFunc = (SetThreadDescription_t)GetProcAddress(GetModuleHandleA("kernel32.dll"), "SetThreadDescription");
|
||||
if (setThreadDescriptionFunc != NULL) {
|
||||
WCHAR nameW[16];
|
||||
size_t chars;
|
||||
@ -46,7 +44,6 @@ void setThreadNameWin32(const char* name) {
|
||||
mbstowcs_s(&chars, nameW, ARRAYSIZE(nameW), name, _TRUNCATE);
|
||||
setThreadDescriptionFunc(GetCurrentThread(), nameW);
|
||||
}
|
||||
FreeLibrary(hKernel32);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// This method works on legacy OSes and older tools not updated to use SetThreadDescription yet,
|
||||
|
Loading…
x
Reference in New Issue
Block a user