aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-05-20 21:44:14 -0400
committerDavid Robillard <d@drobilla.net>2022-05-20 21:45:02 -0400
commita8a0fed38c2b5a6fc479c26dbd9fba7b23879c9e (patch)
tree282af0862a4d09acc02ea317c50055278cb6004b
parentc07a3d32baec8c546c6778016de61db00bd869f5 (diff)
downloadpugl-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.c12
1 files 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);