diff options
author | David Robillard <d@drobilla.net> | 2022-05-20 21:44:14 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-05-20 21:45:02 -0400 |
commit | a8a0fed38c2b5a6fc479c26dbd9fba7b23879c9e (patch) | |
tree | 282af0862a4d09acc02ea317c50055278cb6004b | |
parent | c07a3d32baec8c546c6778016de61db00bd869f5 (diff) | |
download | pugl-a8a0fed38c2b5a6fc479c26dbd9fba7b23879c9e.tar.gz pugl-a8a0fed38c2b5a6fc479c26dbd9fba7b23879c9e.tar.bz2 pugl-a8a0fed38c2b5a6fc479c26dbd9fba7b23879c9e.zip |
Windows: Set window class on local module
This avoids potential clashes between multiple copies of Pugl statically
compiled into several modules.
-rw-r--r-- | src/win.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -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); |