Windows hook proc thunk management simplified.
This commit is contained in:
parent
2dec1ba403
commit
f4edf2378e
|
@ -1154,15 +1154,20 @@ LRESULT WINAPI ShellHookProc16(INT16 code, WPARAM16 wParam, LPARAM lParam)
|
||||||
* RegisterShellHook [SHELL.102]
|
* RegisterShellHook [SHELL.102]
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI RegisterShellHook16(HWND16 hWnd, UINT16 uAction)
|
BOOL WINAPI RegisterShellHook16(HWND16 hWnd, UINT16 uAction)
|
||||||
{ TRACE_(shell)("%04x [%u]\n", hWnd, uAction );
|
{
|
||||||
|
TRACE_(shell)("%04x [%u]\n", hWnd, uAction );
|
||||||
|
|
||||||
switch( uAction )
|
switch( uAction )
|
||||||
{ case 2: /* register hWnd as a shell window */
|
{
|
||||||
|
case 2: /* register hWnd as a shell window */
|
||||||
if( !SHELL_hHook )
|
if( !SHELL_hHook )
|
||||||
{ HMODULE16 hShell = GetModuleHandle16( "SHELL" );
|
{
|
||||||
SHELL_hHook = SetWindowsHookEx16( WH_SHELL, ShellHookProc16, hShell, 0 );
|
HMODULE16 hShell = GetModuleHandle16( "SHELL" );
|
||||||
if( SHELL_hHook )
|
HOOKPROC16 hookProc = (HOOKPROC16)NE_GetEntryPoint( hShell, 103 );
|
||||||
{ uMsgWndCreated = RegisterWindowMessageA( lpstrMsgWndCreated );
|
SHELL_hHook = SetWindowsHookEx16( WH_SHELL, hookProc, hShell, 0 );
|
||||||
|
if ( SHELL_hHook )
|
||||||
|
{
|
||||||
|
uMsgWndCreated = RegisterWindowMessageA( lpstrMsgWndCreated );
|
||||||
uMsgWndDestroyed = RegisterWindowMessageA( lpstrMsgWndDestroyed );
|
uMsgWndDestroyed = RegisterWindowMessageA( lpstrMsgWndDestroyed );
|
||||||
uMsgShellActivate = RegisterWindowMessageA( lpstrMsgShellActivate );
|
uMsgShellActivate = RegisterWindowMessageA( lpstrMsgShellActivate );
|
||||||
}
|
}
|
||||||
|
@ -1170,14 +1175,13 @@ BOOL WINAPI RegisterShellHook16(HWND16 hWnd, UINT16 uAction)
|
||||||
WARN_(shell)("-- unable to install ShellHookProc()!\n");
|
WARN_(shell)("-- unable to install ShellHookProc()!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if( SHELL_hHook )
|
if ( SHELL_hHook )
|
||||||
return ((SHELL_hWnd = hWnd) != 0);
|
return ((SHELL_hWnd = hWnd) != 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
WARN_(shell)("-- unknown code %i\n", uAction );
|
WARN_(shell)("-- unknown code %i\n", uAction );
|
||||||
/* just in case */
|
SHELL_hWnd = 0; /* just in case */
|
||||||
SHELL_hWnd = 0;
|
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ file user.exe
|
||||||
117 pascal16 WindowFromDC(word) WindowFromDC16
|
117 pascal16 WindowFromDC(word) WindowFromDC16
|
||||||
119 pascal GetMessagePos() GetMessagePos
|
119 pascal GetMessagePos() GetMessagePos
|
||||||
120 pascal GetMessageTime() GetMessageTime
|
120 pascal GetMessageTime() GetMessageTime
|
||||||
121 pascal SetWindowsHook(s_word segptr) THUNK_SetWindowsHook16
|
121 pascal SetWindowsHook(s_word segptr) SetWindowsHook16
|
||||||
122 pascal CallWindowProc(segptr word word word long) CallWindowProc16
|
122 pascal CallWindowProc(segptr word word word long) CallWindowProc16
|
||||||
123 pascal16 CallMsgFilter(segptr s_word) CallMsgFilter16
|
123 pascal16 CallMsgFilter(segptr s_word) CallMsgFilter16
|
||||||
124 pascal16 UpdateWindow(word) UpdateWindow16
|
124 pascal16 UpdateWindow(word) UpdateWindow16
|
||||||
|
@ -236,7 +236,7 @@ file user.exe
|
||||||
231 pascal16 GetSystemDebugState() GetSystemDebugState16
|
231 pascal16 GetSystemDebugState() GetSystemDebugState16
|
||||||
232 pascal16 SetWindowPos(word word word word word word word) SetWindowPos16
|
232 pascal16 SetWindowPos(word word word word word word word) SetWindowPos16
|
||||||
233 pascal16 SetParent(word word) SetParent16
|
233 pascal16 SetParent(word word) SetParent16
|
||||||
234 pascal16 UnhookWindowsHook(s_word segptr) THUNK_UnhookWindowsHook16
|
234 pascal16 UnhookWindowsHook(s_word segptr) UnhookWindowsHook16
|
||||||
235 pascal DefHookProc(s_word word long ptr) DefHookProc16
|
235 pascal DefHookProc(s_word word long ptr) DefHookProc16
|
||||||
236 pascal16 GetCapture() GetCapture16
|
236 pascal16 GetCapture() GetCapture16
|
||||||
237 pascal16 GetUpdateRgn(word word word) GetUpdateRgn16
|
237 pascal16 GetUpdateRgn(word word word) GetUpdateRgn16
|
||||||
|
@ -296,8 +296,8 @@ file user.exe
|
||||||
288 pascal GetMessageExtraInfo() GetMessageExtraInfo
|
288 pascal GetMessageExtraInfo() GetMessageExtraInfo
|
||||||
289 register keybd_event() WIN16_keybd_event
|
289 register keybd_event() WIN16_keybd_event
|
||||||
290 pascal16 RedrawWindow(word ptr word word) RedrawWindow16
|
290 pascal16 RedrawWindow(word ptr word word) RedrawWindow16
|
||||||
291 pascal SetWindowsHookEx(s_word segptr word word) THUNK_SetWindowsHookEx16
|
291 pascal SetWindowsHookEx(s_word segptr word word) SetWindowsHookEx16
|
||||||
292 pascal16 UnhookWindowsHookEx(segptr) THUNK_UnhookWindowsHookEx16
|
292 pascal16 UnhookWindowsHookEx(segptr) UnhookWindowsHookEx16
|
||||||
293 pascal CallNextHookEx(segptr s_word word long) CallNextHookEx16
|
293 pascal CallNextHookEx(segptr s_word word long) CallNextHookEx16
|
||||||
294 pascal16 LockWindowUpdate(word) LockWindowUpdate16
|
294 pascal16 LockWindowUpdate(word) LockWindowUpdate16
|
||||||
299 register mouse_event() WIN16_mouse_event
|
299 register mouse_event() WIN16_mouse_event
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
/* hook type mask */
|
/* hook type mask */
|
||||||
#define HOOK_MAPTYPE (HOOK_WIN16 | HOOK_WIN32A | HOOK_WIN32W)
|
#define HOOK_MAPTYPE (HOOK_WIN16 | HOOK_WIN32A | HOOK_WIN32W)
|
||||||
|
|
||||||
extern HOOKPROC16 HOOK_GetProc16( HHOOK hhook );
|
|
||||||
extern BOOL HOOK_IsHooked( INT16 id );
|
extern BOOL HOOK_IsHooked( INT16 id );
|
||||||
extern LRESULT HOOK_CallHooks16( INT16 id, INT16 code, WPARAM16 wParam,
|
extern LRESULT HOOK_CallHooks16( INT16 id, INT16 code, WPARAM16 wParam,
|
||||||
LPARAM lParam );
|
LPARAM lParam );
|
||||||
|
@ -29,6 +28,5 @@ extern LRESULT HOOK_CallHooksW( INT id, INT code, WPARAM wParam,
|
||||||
extern void HOOK_FreeModuleHooks( HMODULE16 hModule );
|
extern void HOOK_FreeModuleHooks( HMODULE16 hModule );
|
||||||
extern void HOOK_FreeQueueHooks( HQUEUE16 hQueue );
|
extern void HOOK_FreeQueueHooks( HQUEUE16 hQueue );
|
||||||
extern void HOOK_ResetQueueHooks( HQUEUE16 hQueue );
|
extern void HOOK_ResetQueueHooks( HQUEUE16 hQueue );
|
||||||
extern HOOKPROC HOOK_GetProc( HHOOK hook );
|
|
||||||
|
|
||||||
#endif /* __WINE_HOOK_H */
|
#endif /* __WINE_HOOK_H */
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
Makefile
|
Makefile
|
||||||
|
hook.glue.c
|
||||||
|
|
|
@ -41,6 +41,8 @@ C_SRCS = \
|
||||||
winpos.c \
|
winpos.c \
|
||||||
winproc.c
|
winproc.c
|
||||||
|
|
||||||
|
GLUE = hook.c
|
||||||
|
|
||||||
all: $(MODULE).o
|
all: $(MODULE).o
|
||||||
|
|
||||||
@MAKE_RULES@
|
@MAKE_RULES@
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "winuser.h"
|
#include "winuser.h"
|
||||||
#include "wine/winuser16.h"
|
#include "wine/winuser16.h"
|
||||||
#include "wine/winbase16.h"
|
#include "wine/winbase16.h"
|
||||||
|
#include "callback.h"
|
||||||
#include "hook.h"
|
#include "hook.h"
|
||||||
#include "win.h"
|
#include "win.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
@ -35,11 +36,12 @@ DEFAULT_DEBUG_CHANNEL(hook)
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
HANDLE16 next; /* 00 Next hook in chain */
|
HANDLE16 next; /* 00 Next hook in chain */
|
||||||
HOOKPROC proc WINE_PACKED; /* 02 Hook procedure */
|
HOOKPROC proc; /* 02 Hook procedure (original) */
|
||||||
INT16 id; /* 06 Hook id (WH_xxx) */
|
INT16 id; /* 06 Hook id (WH_xxx) */
|
||||||
HQUEUE16 ownerQueue; /* 08 Owner queue (0 for system hook) */
|
HQUEUE16 ownerQueue; /* 08 Owner queue (0 for system hook) */
|
||||||
HMODULE16 ownerModule; /* 0a Owner module */
|
HMODULE16 ownerModule; /* 0a Owner module */
|
||||||
WORD flags; /* 0c flags */
|
WORD flags; /* 0c flags */
|
||||||
|
HOOKPROC thunk; /* 0e Hook procedure (CallTo16 thunk) */
|
||||||
} HOOKDATA;
|
} HOOKDATA;
|
||||||
|
|
||||||
#include "poppack.h"
|
#include "poppack.h"
|
||||||
|
@ -850,6 +852,9 @@ static HANDLE16 HOOK_GetHook( INT16 id, HQUEUE16 hQueue )
|
||||||
*
|
*
|
||||||
* Install a given hook.
|
* Install a given hook.
|
||||||
*/
|
*/
|
||||||
|
/* ### start build ### */
|
||||||
|
extern LONG CALLBACK HOOK_CallTo16_long_wwl(FARPROC16,WORD,WORD,LONG);
|
||||||
|
/* ### stop build ### */
|
||||||
static HHOOK HOOK_SetHook( INT16 id, LPVOID proc, INT type,
|
static HHOOK HOOK_SetHook( INT16 id, LPVOID proc, INT type,
|
||||||
HMODULE16 hModule, DWORD dwThreadId )
|
HMODULE16 hModule, DWORD dwThreadId )
|
||||||
{
|
{
|
||||||
|
@ -885,6 +890,20 @@ static HHOOK HOOK_SetHook( INT16 id, LPVOID proc, INT type,
|
||||||
data->ownerModule = hModule;
|
data->ownerModule = hModule;
|
||||||
data->flags = type;
|
data->flags = type;
|
||||||
|
|
||||||
|
/* Create CallTo16 thunk for 16-bit hooks */
|
||||||
|
|
||||||
|
if ( (data->flags & HOOK_MAPTYPE) == HOOK_WIN16 )
|
||||||
|
data->thunk = (HOOKPROC)THUNK_Alloc( (FARPROC16)data->proc,
|
||||||
|
(RELAY)HOOK_CallTo16_long_wwl );
|
||||||
|
else
|
||||||
|
data->thunk = data->proc;
|
||||||
|
|
||||||
|
if ( !data->thunk && data->proc )
|
||||||
|
{
|
||||||
|
USER_HEAP_FREE( handle );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Insert it in the correct linked list */
|
/* Insert it in the correct linked list */
|
||||||
|
|
||||||
if (hQueue)
|
if (hQueue)
|
||||||
|
@ -945,6 +964,10 @@ static BOOL HOOK_RemoveHook( HANDLE16 hook )
|
||||||
|
|
||||||
if (!*prevHook) return FALSE;
|
if (!*prevHook) return FALSE;
|
||||||
*prevHook = data->next;
|
*prevHook = data->next;
|
||||||
|
|
||||||
|
if ( (data->flags & HOOK_MAPTYPE) == HOOK_WIN16 )
|
||||||
|
THUNK_Free( (FARPROC)data->thunk );
|
||||||
|
|
||||||
USER_HEAP_FREE( hook );
|
USER_HEAP_FREE( hook );
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -1004,7 +1027,7 @@ static LRESULT HOOK_CallHook( HANDLE16 hook, INT fromtype, INT code,
|
||||||
/* Suspend window structure locks before calling user code */
|
/* Suspend window structure locks before calling user code */
|
||||||
iWndsLocks = WIN_SuspendWndsLock();
|
iWndsLocks = WIN_SuspendWndsLock();
|
||||||
|
|
||||||
ret = data->proc(code, wParam, lParam);
|
ret = data->thunk(code, wParam, lParam);
|
||||||
|
|
||||||
/* Grrr. While the hook procedure is supposed to have an LRESULT return
|
/* Grrr. While the hook procedure is supposed to have an LRESULT return
|
||||||
value even in Win16, it seems that for those hook types where the
|
value even in Win16, it seems that for those hook types where the
|
||||||
|
@ -1036,21 +1059,6 @@ static LRESULT HOOK_CallHook( HANDLE16 hook, INT fromtype, INT code,
|
||||||
* Exported Functions & APIs
|
* Exported Functions & APIs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* HOOK_GetProc16
|
|
||||||
*
|
|
||||||
* Don't call this unless you are the if1632/thunk.c.
|
|
||||||
*/
|
|
||||||
HOOKPROC16 HOOK_GetProc16( HHOOK hhook )
|
|
||||||
{
|
|
||||||
HOOKDATA *data;
|
|
||||||
if (HIWORD(hhook) != HOOK_MAGIC) return NULL;
|
|
||||||
if (!(data = (HOOKDATA *)USER_HEAP_LIN_ADDR( LOWORD(hhook) ))) return NULL;
|
|
||||||
if ((data->flags & HOOK_MAPTYPE) != HOOK_WIN16) return NULL;
|
|
||||||
return (HOOKPROC16)data->proc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* HOOK_IsHooked
|
* HOOK_IsHooked
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue