From: Jacek Caban Subject: urlmon: Unregister window class on DLL unload. Message-Id: <52FCC6E8.6090006@codeweavers.com> Date: Thu, 13 Feb 2014 14:21:44 +0100 --- dlls/urlmon/bindprot.c | 64 +++++++++++++++++++++++++++++++---------------- dlls/urlmon/urlmon_main.c | 1 + dlls/urlmon/urlmon_main.h | 1 + 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/dlls/urlmon/bindprot.c b/dlls/urlmon/bindprot.c index b11856b..dc0d7cd 100644 --- a/dlls/urlmon/bindprot.c +++ b/dlls/urlmon/bindprot.c @@ -83,15 +83,50 @@ static LRESULT WINAPI notif_wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM return DefWindowProcW(hwnd, msg, wParam, lParam); } +static const WCHAR wszURLMonikerNotificationWindow[] = + {'U','R','L',' ','M','o','n','i','k','e','r',' ', + 'N','o','t','i','f','i','c','a','t','i','o','n',' ','W','i','n','d','o','w',0}; + +static ATOM notif_wnd_class; + +static CRITICAL_SECTION notif_wnd_class_cs; +static CRITICAL_SECTION_DEBUG notif_wnd_class_cs_dbg = { + 0, 0, ¬if_wnd_class_cs, + { ¬if_wnd_class_cs_dbg.ProcessLocksList, ¬if_wnd_class_cs_dbg.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": notif_wnd_class") } +}; +static CRITICAL_SECTION notif_wnd_class_cs = { ¬if_wnd_class_cs_dbg, -1, 0, 0, 0, 0 }; + +static BOOL ensure_notif_wnd_class(void) +{ + EnterCriticalSection(¬if_wnd_class_cs); + + if(!notif_wnd_class) { + static WNDCLASSEXW wndclass = { + sizeof(wndclass), 0, notif_wnd_proc, 0, 0, + NULL, NULL, NULL, NULL, NULL, + wszURLMonikerNotificationWindow, NULL + }; + + wndclass.hInstance = hProxyDll; + notif_wnd_class = RegisterClassExW(&wndclass); + } + + LeaveCriticalSection(¬if_wnd_class_cs); + + return notif_wnd_class != 0; +} + +void unregister_notif_wnd_class(void) +{ + if(notif_wnd_class) + UnregisterClassW(MAKEINTRESOURCEW(notif_wnd_class), hProxyDll); +} + HWND get_notif_hwnd(void) { - static ATOM wnd_class = 0; tls_data_t *tls_data; - static const WCHAR wszURLMonikerNotificationWindow[] = - {'U','R','L',' ','M','o','n','i','k','e','r',' ', - 'N','o','t','i','f','i','c','a','t','i','o','n',' ','W','i','n','d','o','w',0}; - tls_data = get_tls_data(); if(!tls_data) return NULL; @@ -101,23 +136,10 @@ HWND get_notif_hwnd(void) return tls_data->notif_hwnd; } - if(!wnd_class) { - static WNDCLASSEXW wndclass = { - sizeof(wndclass), 0, - notif_wnd_proc, 0, 0, - NULL, NULL, NULL, NULL, NULL, - wszURLMonikerNotificationWindow, - NULL - }; - - wndclass.hInstance = hProxyDll; - - wnd_class = RegisterClassExW(&wndclass); - if (!wnd_class && GetLastError() == ERROR_CLASS_ALREADY_EXISTS) - wnd_class = 1; - } + if(!ensure_notif_wnd_class()) + return NULL; - tls_data->notif_hwnd = CreateWindowExW(0, wszURLMonikerNotificationWindow, + tls_data->notif_hwnd = CreateWindowExW(0, MAKEINTRESOURCEW(notif_wnd_class), wszURLMonikerNotificationWindow, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hProxyDll, NULL); if(tls_data->notif_hwnd) diff --git a/dlls/urlmon/urlmon_main.c b/dlls/urlmon/urlmon_main.c index 7b3f1fd..1204a62 100644 --- a/dlls/urlmon/urlmon_main.c +++ b/dlls/urlmon/urlmon_main.c @@ -139,6 +139,7 @@ static void process_detach(void) free_session(); free_tls_list(); + unregister_notif_wnd_class(); } /*********************************************************************** diff --git a/dlls/urlmon/urlmon_main.h b/dlls/urlmon/urlmon_main.h index faab45a..14a4f08 100644 --- a/dlls/urlmon/urlmon_main.h +++ b/dlls/urlmon/urlmon_main.h @@ -225,6 +225,7 @@ typedef struct { tls_data_t *get_tls_data(void) DECLSPEC_HIDDEN; +void unregister_notif_wnd_class(void) DECLSPEC_HIDDEN; HWND get_notif_hwnd(void) DECLSPEC_HIDDEN; void release_notif_hwnd(HWND) DECLSPEC_HIDDEN;