From e557f48cdf6ef1eafe468829ec9298a3eb6ac80b Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 17 Feb 2022 15:42:36 +0100 Subject: [PATCH] win32u: Set user callbacks from user32 DllMain. Signed-off-by: Jacek Caban Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/user32/user_main.c | 11 ++++++ dlls/win32u/driver.c | 12 +----- dlls/win32u/ntuser_private.h | 9 +++++ dlls/win32u/palette.c | 11 +----- dlls/win32u/region.c | 7 +--- dlls/win32u/sysparams.c | 2 + dlls/win32u/win32u_private.h | 9 ----- dlls/win32u/wrappers.c | 73 +----------------------------------- include/ntuser.h | 1 + 9 files changed, 28 insertions(+), 107 deletions(-) diff --git a/dlls/user32/user_main.c b/dlls/user32/user_main.c index c2ec561a800..a91db57cdb4 100644 --- a/dlls/user32/user_main.c +++ b/dlls/user32/user_main.c @@ -208,6 +208,14 @@ static void dpiaware_init(void) } } +static const struct user_callbacks user_funcs = +{ + GetDesktopWindow, + GetWindowRect, + RedrawWindow, + SendMessageTimeoutW, + WindowFromDC, +}; static const void *kernel_callback_table[NtUserCallCount] = { @@ -223,6 +231,9 @@ static BOOL process_attach(void) { NtCurrentTeb()->Peb->KernelCallbackTable = kernel_callback_table; + /* FIXME: should not be needed */ + NtUserCallOneParam( (UINT_PTR)&user_funcs, NtUserSetCallbacks ); + dpiaware_init(); register_desktop_class(); diff --git a/dlls/win32u/driver.c b/dlls/win32u/driver.c index b3a3e70f83f..5e6cee33bc6 100644 --- a/dlls/win32u/driver.c +++ b/dlls/win32u/driver.c @@ -24,21 +24,13 @@ #endif #include -#include -#include -#include #include #include "ntstatus.h" #define WIN32_NO_STATUS -#include "windef.h" -#include "winbase.h" -#include "wingdi.h" -#include "winreg.h" -#include "wine/winbase16.h" -#include "winuser.h" - #include "ntgdi_private.h" +#include "ntuser_private.h" +#include "wine/winbase16.h" #include "wine/list.h" #include "wine/debug.h" diff --git a/dlls/win32u/ntuser_private.h b/dlls/win32u/ntuser_private.h index fec04d94948..f0e0f8835bf 100644 --- a/dlls/win32u/ntuser_private.h +++ b/dlls/win32u/ntuser_private.h @@ -24,6 +24,15 @@ #include "ntuser.h" +struct user_callbacks +{ + HWND (WINAPI *pGetDesktopWindow)(void); + BOOL (WINAPI *pGetWindowRect)( HWND hwnd, LPRECT rect ); + BOOL (WINAPI *pRedrawWindow)( HWND, const RECT*, HRGN, UINT ); + LRESULT (WINAPI *pSendMessageTimeoutW)( HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR ); + HWND (WINAPI *pWindowFromDC)( HDC ); +}; + /* this is the structure stored in TEB->Win32ClientInfo */ /* no attempt is made to keep the layout compatible with the Windows one */ struct user_thread_info diff --git a/dlls/win32u/palette.c b/dlls/win32u/palette.c index 3aeda89851f..1c2f2c70434 100644 --- a/dlls/win32u/palette.c +++ b/dlls/win32u/palette.c @@ -27,17 +27,8 @@ #pragma makedep unix #endif -#include -#include -#include - -#include "windef.h" -#include "winbase.h" -#include "winerror.h" -#include "wingdi.h" -#include "winuser.h" - #include "ntgdi_private.h" +#include "ntuser_private.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(palette); diff --git a/dlls/win32u/region.c b/dlls/win32u/region.c index 86554f21e1c..17eae861cbf 100644 --- a/dlls/win32u/region.c +++ b/dlls/win32u/region.c @@ -99,13 +99,8 @@ SOFTWARE. #endif #include -#include -#include -#include -#include "windef.h" -#include "winbase.h" -#include "wingdi.h" #include "ntgdi_private.h" +#include "ntuser_private.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(region); diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c index c9885f89d87..7af1e20f008 100644 --- a/dlls/win32u/sysparams.c +++ b/dlls/win32u/sysparams.c @@ -4544,6 +4544,8 @@ ULONG_PTR WINAPI NtUserCallOneParam( ULONG_PTR arg, ULONG code ) return get_entry( &entry_DESKPATTERN, 256, (WCHAR *)arg ); case NtUserIncrementKeyStateCounter: return InterlockedAdd( &global_key_state_counter, arg ); + case NtUserSetCallbacks: + return (UINT_PTR)InterlockedExchangePointer( (void **)&user_callbacks, (void *)arg ); default: FIXME( "invalid code %u\n", code ); return 0; diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index c3419d83858..3017b7e6a72 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -30,15 +30,6 @@ #include "wine/unixlib.h" #include "wine/debug.h" -struct user_callbacks -{ - HWND (WINAPI *pGetDesktopWindow)(void); - BOOL (WINAPI *pGetWindowRect)( HWND hwnd, LPRECT rect ); - BOOL (WINAPI *pRedrawWindow)( HWND, const RECT*, HRGN, UINT ); - LRESULT (WINAPI *pSendMessageTimeoutW)( HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR ); - HWND (WINAPI *pWindowFromDC)( HDC ); -}; - extern const struct user_callbacks *user_callbacks DECLSPEC_HIDDEN; struct unix_funcs diff --git a/dlls/win32u/wrappers.c b/dlls/win32u/wrappers.c index 2823eae9fe1..922e5a26b00 100644 --- a/dlls/win32u/wrappers.c +++ b/dlls/win32u/wrappers.c @@ -947,79 +947,8 @@ void CDECL __wine_set_display_driver( struct user_driver_funcs *funcs, UINT vers return unix_funcs->set_display_driver( funcs, version ); } -static void *get_user_proc( const char *name, BOOL force_load ) -{ - ANSI_STRING name_str; - FARPROC proc = NULL; - static HMODULE user32; - - if (!user32) - { - UNICODE_STRING str; - NTSTATUS status; - RtlInitUnicodeString( &str, L"user32.dll" ); - status = force_load - ? LdrLoadDll( NULL, 0, &str, &user32 ) - : LdrGetDllHandle( NULL, 0, &str, &user32 ); - if (status < 0) return NULL; - } - RtlInitAnsiString( &name_str, name ); - LdrGetProcedureAddress( user32, &name_str, 0, (void**)&proc ); - return proc; -} - -static HWND WINAPI call_GetDesktopWindow(void) -{ - static HWND (WINAPI *pGetDesktopWindow)(void); - if (!pGetDesktopWindow) - pGetDesktopWindow = get_user_proc( "GetDesktopWindow", TRUE ); - return pGetDesktopWindow ? pGetDesktopWindow() : NULL; -} - -static BOOL WINAPI call_GetWindowRect( HWND hwnd, LPRECT rect ) -{ - static BOOL (WINAPI *pGetWindowRect)( HWND hwnd, LPRECT rect ); - if (!pGetWindowRect) - pGetWindowRect = get_user_proc( "GetWindowRect", FALSE ); - return pGetWindowRect && pGetWindowRect( hwnd, rect ); -} - -static BOOL WINAPI call_RedrawWindow( HWND hwnd, const RECT *rect, HRGN rgn, UINT flags ) -{ - static BOOL (WINAPI *pRedrawWindow)( HWND, const RECT*, HRGN, UINT ); - if (!pRedrawWindow) - pRedrawWindow = get_user_proc( "RedrawWindow", FALSE ); - return pRedrawWindow && pRedrawWindow( hwnd, rect, rgn, flags ); -} - -static LRESULT WINAPI call_SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, - UINT flags, UINT timeout, PDWORD_PTR res_ptr ) -{ - static LRESULT (WINAPI *pSendMessageTimeoutW)( HWND, UINT, WPARAM, LPARAM, UINT, UINT, PDWORD_PTR ); - if (!pSendMessageTimeoutW) pSendMessageTimeoutW = get_user_proc( "SendMessageTimeoutW", FALSE ); - if (!pSendMessageTimeoutW) return 0; - return pSendMessageTimeoutW( hwnd, msg, wparam, lparam, flags, timeout, res_ptr ); -} - -static HWND WINAPI call_WindowFromDC( HDC hdc ) -{ - static HWND (WINAPI *pWindowFromDC)( HDC ); - if (!pWindowFromDC) - pWindowFromDC = get_user_proc( "WindowFromDC", FALSE ); - return pWindowFromDC ? pWindowFromDC( hdc ) : NULL; -} - -static const struct user_callbacks user_funcs = -{ - call_GetDesktopWindow, - call_GetWindowRect, - call_RedrawWindow, - call_SendMessageTimeoutW, - call_WindowFromDC, -}; - extern void wrappers_init( unixlib_handle_t handle ) { - const void *args = &user_funcs; + const void *args; if (!__wine_unix_call( handle, 1, &args )) unix_funcs = args; } diff --git a/include/ntuser.h b/include/ntuser.h index 6e4183b1e14..6e941c29c6d 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -85,6 +85,7 @@ enum NtUserFlushWindowSurfaces, NtUserGetDeskPattern, NtUserIncrementKeyStateCounter, + NtUserSetCallbacks, }; /* NtUserCallTwoParam codes, not compatible with Windows */