From 9b9f97e3f668c9d291b4f9fa2944ddb11509970f Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Tue, 20 Mar 2018 10:44:01 +0300 Subject: [PATCH] user32: Add redirected class registration callback. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/comctl32/comctl32.spec | 1 + dlls/comctl32/commctrl.c | 42 +++++++++++++++++++++++++----- dlls/user32/class.c | 52 ++++++++++++++++++++++++++++++------- dlls/user32/user_private.h | 3 ++- dlls/user32/win.c | 2 +- 5 files changed, 81 insertions(+), 19 deletions(-) diff --git a/dlls/comctl32/comctl32.spec b/dlls/comctl32/comctl32.spec index 4e1aeadf1df..34d9e7650d3 100644 --- a/dlls/comctl32/comctl32.spec +++ b/dlls/comctl32/comctl32.spec @@ -194,5 +194,6 @@ @ stdcall PropertySheet(ptr) PropertySheetA @ stdcall PropertySheetA(ptr) @ stdcall PropertySheetW(ptr) +@ stdcall RegisterClassNameW(wstr) @ stdcall UninitializeFlatSB(long) @ stdcall _TrackMouseEvent(ptr) diff --git a/dlls/comctl32/commctrl.c b/dlls/comctl32/commctrl.c index 9356624a130..1117ec43e91 100644 --- a/dlls/comctl32/commctrl.c +++ b/dlls/comctl32/commctrl.c @@ -69,6 +69,7 @@ #include "shlwapi.h" #include "comctl32.h" #include "wine/debug.h" +#include "wine/unicode.h" WINE_DEFAULT_DEBUG_CHANNEL(commctrl); @@ -113,6 +114,40 @@ static void unregister_versioned_classes(void) #undef VERSION } +BOOL WINAPI RegisterClassNameW(const WCHAR *class) +{ + static const struct + { + const WCHAR nameW[16]; + void (*fn_register)(void); + } + classes[] = + { + { {'B','u','t','t','o','n',0}, BUTTON_Register }, + { {'C','o','m','b','o','B','o','x',0}, COMBO_Register }, + { {'C','o','m','b','o','L','B','o','x',0}, COMBOLBOX_Register }, + { {'E','d','i','t',0}, EDIT_Register }, + { {'L','i','s','t','B','o','x',0}, LISTBOX_Register }, + { {'S','t','a','t','i','c',0}, STATIC_Register }, + }; + + int min = 0, max = ARRAY_SIZE(classes) - 1; + + while (min <= max) + { + int res, pos = (min + max) / 2; + if (!(res = strcmpiW(class, classes[pos].nameW))) + { + classes[pos].fn_register(); + return TRUE; + } + if (res < 0) max = pos - 1; + else min = pos + 1; + } + + return FALSE; +} + /*********************************************************************** * DllMain [Internal] * @@ -172,13 +207,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) TREEVIEW_Register (); UPDOWN_Register (); - BUTTON_Register (); - COMBO_Register (); - COMBOLBOX_Register (); - EDIT_Register (); - LISTBOX_Register (); - STATIC_Register (); - /* subclass user32 controls */ THEMING_Initialize (); break; diff --git a/dlls/user32/class.c b/dlls/user32/class.c index e733cc2ce2e..a8b5a8fe5cb 100644 --- a/dlls/user32/class.c +++ b/dlls/user32/class.c @@ -320,7 +320,7 @@ static void CLASS_FreeClass( CLASS *classPtr ) USER_Unlock(); } -const WCHAR *CLASS_GetVersionedName( const WCHAR *name, UINT *basename_offset ) +const WCHAR *CLASS_GetVersionedName( const WCHAR *name, UINT *basename_offset, BOOL register_class ) { ACTCTX_SECTION_KEYED_DATA data; struct wndclass_redirect_data @@ -332,7 +332,8 @@ const WCHAR *CLASS_GetVersionedName( const WCHAR *name, UINT *basename_offset ) ULONG module_len; ULONG module_offset; } *wndclass; - const WCHAR *module; + const WCHAR *module, *ret; + HMODULE hmod; if (basename_offset) *basename_offset = 0; @@ -352,10 +353,42 @@ const WCHAR *CLASS_GetVersionedName( const WCHAR *name, UINT *basename_offset ) *basename_offset = wndclass->name_len / sizeof(WCHAR) - strlenW(name); module = (const WCHAR *)((BYTE *)data.lpSectionBase + wndclass->module_offset); - if (!GetModuleHandleW( module )) - LoadLibraryW( module ); + if (!(hmod = GetModuleHandleW( module ))) + hmod = LoadLibraryW( module ); - return (const WCHAR *)((BYTE *)wndclass + wndclass->name_offset); + ret = (const WCHAR *)((BYTE *)wndclass + wndclass->name_offset); + + if (register_class && hmod) + { + BOOL found = FALSE; + struct list *ptr; + + USER_Lock(); + + LIST_FOR_EACH( ptr, &class_list ) + { + CLASS *class = LIST_ENTRY( ptr, CLASS, entry ); + if (strcmpiW( class->name, ret )) continue; + if (!class->local || class->hInstance == hmod) + { + found = TRUE; + break; + } + } + + USER_Unlock(); + + if (!found) + { + BOOL (WINAPI *pRegisterClassNameW)(const WCHAR *class); + + pRegisterClassNameW = (void *)GetProcAddress(hmod, "RegisterClassNameW"); + if (pRegisterClassNameW) + pRegisterClassNameW(name); + } + } + + return ret; } /*********************************************************************** @@ -373,7 +406,7 @@ static CLASS *CLASS_FindClass( LPCWSTR name, HINSTANCE hinstance ) if (!name) return NULL; - name = CLASS_GetVersionedName( name, NULL ); + name = CLASS_GetVersionedName( name, NULL, TRUE ); for (;;) { @@ -409,7 +442,6 @@ static CLASS *CLASS_FindClass( LPCWSTR name, HINSTANCE hinstance ) return NULL; } - /*********************************************************************** * CLASS_RegisterClass * @@ -646,7 +678,7 @@ ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc ) { UINT basename_offset; if (!MultiByteToWideChar( CP_ACP, 0, wc->lpszClassName, -1, name, MAX_ATOM_LEN + 1 )) return 0; - classname = CLASS_GetVersionedName( name, &basename_offset ); + classname = CLASS_GetVersionedName( name, &basename_offset, FALSE ); classPtr = CLASS_RegisterClass( classname, basename_offset, instance, !(wc->style & CS_GLOBALCLASS), wc->style, wc->cbClsExtra, wc->cbWndExtra ); } @@ -700,7 +732,7 @@ ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc ) } if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL ); - classname = CLASS_GetVersionedName( wc->lpszClassName, &basename_offset ); + classname = CLASS_GetVersionedName( wc->lpszClassName, &basename_offset, FALSE ); if (!(classPtr = CLASS_RegisterClass( classname, basename_offset, instance, !(wc->style & CS_GLOBALCLASS), wc->style, wc->cbClsExtra, wc->cbWndExtra ))) return 0; @@ -753,7 +785,7 @@ BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance ) GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */ - className = CLASS_GetVersionedName( className, NULL ); + className = CLASS_GetVersionedName( className, NULL, FALSE ); SERVER_START_REQ( destroy_class ) { req->instance = wine_server_client_ptr( hInstance ); diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h index f1cc0a87918..7e4f699b253 100644 --- a/dlls/user32/user_private.h +++ b/dlls/user32/user_private.h @@ -269,7 +269,8 @@ extern INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM w extern BOOL WINPROC_call_window( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *result, BOOL unicode, enum wm_char_mapping mapping ) DECLSPEC_HIDDEN; -extern const WCHAR *CLASS_GetVersionedName(const WCHAR *classname, UINT *basename_offset) DECLSPEC_HIDDEN; +extern const WCHAR *CLASS_GetVersionedName(const WCHAR *classname, UINT *basename_offset, + BOOL register_class) DECLSPEC_HIDDEN; /* message spy definitions */ diff --git a/dlls/user32/win.c b/dlls/user32/win.c index 8c89768ef43..3c497f878e9 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -1344,7 +1344,7 @@ HWND WIN_CreateWindowEx( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE module, CBT_CREATEWNDW cbtc; CREATESTRUCTW cbcs; - className = CLASS_GetVersionedName(className, NULL); + className = CLASS_GetVersionedName(className, NULL, TRUE); TRACE("%s %s%s%s ex=%08x style=%08x %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n", unicode ? debugstr_w(cs->lpszName) : debugstr_a((LPCSTR)cs->lpszName),