Commit d76b38ff authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

win32u: Move NtUserSetWinEventHook implementation from user32.

parent 0e37c674
......@@ -709,61 +709,21 @@ HWINEVENTHOOK WINAPI SetWinEventHook(DWORD event_min, DWORD event_max,
HMODULE inst, WINEVENTPROC proc,
DWORD pid, DWORD tid, DWORD flags)
{
HWINEVENTHOOK handle = 0;
WCHAR module[MAX_PATH];
DWORD len;
UNICODE_STRING str;
DWORD len = 0;
TRACE("%d,%d,%p,%p,%08x,%04x,%08x\n", event_min, event_max, inst,
proc, pid, tid, flags);
if (inst)
{
if (!(len = GetModuleFileNameW(inst, module, MAX_PATH)) || len >= MAX_PATH)
inst = 0;
}
if ((flags & WINEVENT_INCONTEXT) && !inst)
{
SetLastError(ERROR_HOOK_NEEDS_HMOD);
return 0;
}
if (event_min > event_max)
if (inst && (!(len = GetModuleFileNameW( inst, module, MAX_PATH )) || len >= MAX_PATH))
{
SetLastError(ERROR_INVALID_HOOK_FILTER);
return 0;
}
/* FIXME: what if the tid or pid belongs to another process? */
if (tid) /* thread-local hook */
inst = 0;
SERVER_START_REQ( set_hook )
{
req->id = WH_WINEVENT;
req->pid = pid;
req->tid = tid;
req->event_min = event_min;
req->event_max = event_max;
req->flags = flags;
req->unicode = 1;
if (inst) /* make proc relative to the module base */
{
req->proc = wine_server_client_ptr( (void *)((char *)proc - (char *)inst) );
wine_server_add_data( req, module, lstrlenW(module) * sizeof(WCHAR) );
}
else req->proc = wine_server_client_ptr( proc );
if (!wine_server_call_err( req ))
{
handle = wine_server_ptr_handle( reply->handle );
get_user_thread_info()->active_hooks = reply->active_hooks;
}
len = 0;
}
SERVER_END_REQ;
TRACE("-> %p\n", handle);
return handle;
str.Buffer = module;
str.Length = str.MaximumLength = len * sizeof(WCHAR);
return NtUserSetWinEventHook( event_min, event_max, inst, &str, proc, pid, tid, flags );
}
static inline BOOL find_first_hook(DWORD id, DWORD event, HWND hwnd, LONG object_id,
......
......@@ -26,11 +26,66 @@
#include "win32u_private.h"
#include "ntuser_private.h"
#include "wine/server.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(hook);
#define WH_WINEVENT (WH_MAXHOOK+1)
/***********************************************************************
* NtUserSetWinEventHook (win32u.@)
*/
HWINEVENTHOOK WINAPI NtUserSetWinEventHook( DWORD event_min, DWORD event_max, HMODULE inst,
UNICODE_STRING *module, WINEVENTPROC proc,
DWORD pid, DWORD tid, DWORD flags )
{
HWINEVENTHOOK handle = 0;
if ((flags & WINEVENT_INCONTEXT) && !inst)
{
SetLastError(ERROR_HOOK_NEEDS_HMOD);
return 0;
}
if (event_min > event_max)
{
SetLastError(ERROR_INVALID_HOOK_FILTER);
return 0;
}
/* FIXME: what if the tid or pid belongs to another process? */
if (tid) inst = 0; /* thread-local hook */
SERVER_START_REQ( set_hook )
{
req->id = WH_WINEVENT;
req->pid = pid;
req->tid = tid;
req->event_min = event_min;
req->event_max = event_max;
req->flags = flags;
req->unicode = 1;
if (inst) /* make proc relative to the module base */
{
req->proc = wine_server_client_ptr( (void *)((char *)proc - (char *)inst) );
wine_server_add_data( req, module->Buffer, module->Length );
}
else req->proc = wine_server_client_ptr( proc );
if (!wine_server_call_err( req ))
{
handle = wine_server_ptr_handle( reply->handle );
get_user_thread_info()->active_hooks = reply->active_hooks;
}
}
SERVER_END_REQ;
TRACE("-> %p\n", handle);
return handle;
}
/***********************************************************************
* NtUserUnhookWinEvent (win32u.@)
*/
BOOL WINAPI NtUserUnhookWinEvent( HWINEVENTHOOK handle )
......
......@@ -139,6 +139,7 @@ static void * const syscalls[] =
NtUserSetProcessWindowStation,
NtUserSetProp,
NtUserSetThreadDesktop,
NtUserSetWinEventHook,
NtUserUnhookWinEvent,
};
......
......@@ -1237,7 +1237,7 @@
@ stub NtUserSetThreadLayoutHandles
@ stub NtUserSetThreadState
@ stub NtUserSetTimer
@ stub NtUserSetWinEventHook
@ stdcall -syscall NtUserSetWinEventHook(long long long ptr ptr long long long)
@ stub NtUserSetWindowArrangement
@ stub NtUserSetWindowBand
@ stub NtUserSetWindowCompositionAttribute
......
......@@ -126,6 +126,7 @@
SYSCALL_ENTRY( NtUserSetProcessWindowStation ) \
SYSCALL_ENTRY( NtUserSetProp ) \
SYSCALL_ENTRY( NtUserSetThreadDesktop ) \
SYSCALL_ENTRY( NtUserSetWinEventHook ) \
SYSCALL_ENTRY( NtUserUnhookWinEvent )
#endif /* __WOW64WIN_SYSCALL_H */
......@@ -356,6 +356,25 @@ NTSTATUS WINAPI wow64_NtUserGetDoubleClickTime( UINT *args )
return NtUserGetDoubleClickTime();
}
NTSTATUS WINAPI wow64_NtUserSetWinEventHook( UINT *args )
{
DWORD event_min = get_ulong( &args );
DWORD event_max = get_ulong( &args );
HMODULE inst = get_handle( &args );
UNICODE_STRING32 *module32 = get_ptr( &args );
WINEVENTPROC proc = get_ptr(&args );
DWORD pid = get_ulong( &args );
DWORD tid = get_ulong( &args );
DWORD flags = get_ulong( &args );
UNICODE_STRING module;
HWINEVENTHOOK ret;
ret = NtUserSetWinEventHook( event_min, event_max, inst,
unicode_str_32to64( &module, module32 ),
proc, pid, tid, flags );
return HandleToUlong( ret );
}
NTSTATUS WINAPI wow64_NtUserUnhookWinEvent( UINT *args )
{
HWINEVENTHOOK handle = get_handle( &args );
......
......@@ -179,6 +179,9 @@ BOOL WINAPI NtUserSetProcessWindowStation( HWINSTA handle );
BOOL WINAPI NtUserSetProp( HWND hwnd, const WCHAR *str, HANDLE handle );
BOOL WINAPI NtUserSetSysColors( INT count, const INT *colors, const COLORREF *values );
BOOL WINAPI NtUserSetThreadDesktop( HDESK handle );
HWINEVENTHOOK WINAPI NtUserSetWinEventHook( DWORD event_min, DWORD event_max, HMODULE inst,
UNICODE_STRING *module, WINEVENTPROC proc,
DWORD pid, DWORD tid, DWORD flags );
INT WINAPI NtUserShowCursor( BOOL show );
BOOL WINAPI NtUserSystemParametersInfo( UINT action, UINT val, void *ptr, UINT winini );
BOOL WINAPI NtUserSystemParametersInfoForDpi( UINT action, UINT val, PVOID ptr, UINT winini, UINT dpi );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment