Alexandre Julliard : dinput: Only register the window class once to avoid race conditions.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Oct 5 13:06:12 CDT 2006


Module: wine
Branch: master
Commit: 09371c75d5538131b6fd57db5c615165b356f23b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=09371c75d5538131b6fd57db5c615165b356f23b

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Oct  5 17:45:45 2006 +0200

dinput: Only register the window class once to avoid race conditions.

---

 dlls/dinput/dinput_main.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index b60cd89..5ac150b 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -754,20 +754,13 @@ static LRESULT CALLBACK dinput_hook_WndP
 static HWND hook_thread_hwnd;
 static LONG hook_thread_refcount;
 
+static const WCHAR classW[]={'H','o','o','k','_','L','L','_','C','L',0};
+
 static DWORD WINAPI hook_thread_proc(void *param)
 {
-    static const WCHAR classW[]={'H','o','o','k','_','L','L','_','C','L',0};
     MSG msg;
-    WNDCLASSEXW wcex;
     HWND hwnd;
 
-    memset(&wcex, 0, sizeof(wcex));
-    wcex.cbSize = sizeof(wcex);
-    wcex.lpfnWndProc = dinput_hook_WndProc;
-    wcex.lpszClassName = classW;
-    wcex.hInstance = GetModuleHandleW(0);
-
-    if (!RegisterClassExW(&wcex)) ERR("Error registering window class\n");
     hwnd = CreateWindowExW(0, classW, NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, 0);
     hook_thread_hwnd = hwnd;
 
@@ -783,7 +776,6 @@ static DWORD WINAPI hook_thread_proc(voi
     }
     else ERR("Error creating message window\n");
 
-    UnregisterClassW(wcex.lpszClassName, wcex.hInstance);
     return 0;
 }
 
@@ -799,8 +791,21 @@ static CRITICAL_SECTION dinput_hook_crit
 static BOOL create_hook_thread(void)
 {
     LONG ref;
+    static ATOM class_atom;
 
     EnterCriticalSection(&dinput_hook_crit);
+
+    if (!class_atom)
+    {
+        WNDCLASSEXW wcex;
+        memset(&wcex, 0, sizeof(wcex));
+        wcex.cbSize = sizeof(wcex);
+        wcex.lpfnWndProc = dinput_hook_WndProc;
+        wcex.lpszClassName = classW;
+        wcex.hInstance = GetModuleHandleW(0);
+        if (!(class_atom = RegisterClassExW(&wcex))) ERR("Error registering window class\n");
+    }
+
     ref = ++hook_thread_refcount;
     TRACE("Refcount %ld\n", ref);
     if (ref == 1)




More information about the wine-cvs mailing list