From a8a0fed38c2b5a6fc479c26dbd9fba7b23879c9e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 20 May 2022 21:44:14 -0400 Subject: Windows: Set window class on local module This avoids potential clashes between multiple copies of Pugl statically compiled into several modules. --- src/win.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/win.c b/src/win.c index 13c8863..737f843 100644 --- a/src/win.c +++ b/src/win.c @@ -69,15 +69,23 @@ puglWideCharToUtf8(const wchar_t* const wstr, size_t* len) static bool puglRegisterWindowClass(const char* name) { + HMODULE module = NULL; + if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCTSTR)puglRegisterWindowClass, + &module)) { + module = GetModuleHandle(NULL); + } + WNDCLASSEX wc = {0}; - if (GetClassInfoEx(GetModuleHandle(NULL), name, &wc)) { + if (GetClassInfoEx(module, name, &wc)) { return true; // Already registered } wc.cbSize = sizeof(wc); wc.style = CS_OWNDC; wc.lpfnWndProc = wndProc; - wc.hInstance = GetModuleHandle(NULL); + wc.hInstance = module; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); -- cgit v1.2.1