blob: dbe1d451bef90c6680d2b0603fed248673bfa908 [file] [log] [blame]
Alexandre Julliard58199531994-04-21 01:20:00 +00001/*
2 * Windows hook functions
3 *
Alexandre Julliardade697e1995-11-26 13:59:11 +00004 * Copyright 1994, 1995 Alexandre Julliard
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00005 * 1996 Andrew Lewycky
Alexandre Julliardade697e1995-11-26 13:59:11 +00006 *
7 * Based on investigations by Alex Korobka
Alexandre Julliard58199531994-04-21 01:20:00 +00008 */
9
Alexandre Julliardade697e1995-11-26 13:59:11 +000010/*
11 * Warning!
12 * A HHOOK is a 32-bit handle for compatibility with Windows 3.0 where it was
13 * a pointer to the next function. Now it is in fact composed of a USER heap
Alexandre Julliard18f92e71996-07-17 20:02:21 +000014 * handle in the low 16 bits and of a HOOK_MAGIC value in the high 16 bits.
Alexandre Julliard58199531994-04-21 01:20:00 +000015 */
16
Jeremy Whited3e22d92000-02-10 19:03:02 +000017#include "windef.h"
François Gouget44a18222000-12-19 04:53:20 +000018#include "winbase.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000019#include "wingdi.h"
Marcus Meissner61afa331999-02-22 10:16:00 +000020#include "winuser.h"
21#include "wine/winuser16.h"
22#include "wine/winbase16.h"
Ulrich Weigandf4edf231999-09-20 18:45:00 +000023#include "callback.h"
Alexandre Julliard58199531994-04-21 01:20:00 +000024#include "hook.h"
Ulrich Weigand4b6b1c31999-05-17 14:55:30 +000025#include "win.h"
Alexandre Julliardb817f4f1996-03-14 18:08:34 +000026#include "queue.h"
Ulrich Weigand1babe5b1998-12-24 15:16:08 +000027#include "task.h"
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000028#include "user.h"
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000029#include "heap.h"
30#include "struct32.h"
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000031#include "winproc.h"
Alexandre Julliard359f497e1999-07-04 16:02:24 +000032#include "debugtools.h"
Alexandre Julliard58199531994-04-21 01:20:00 +000033
Dimitrie O. Paun529da542000-11-27 23:54:25 +000034DEFAULT_DEBUG_CHANNEL(hook);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000035
Patrik Stridvallc7a8dde1999-04-25 12:36:53 +000036#include "pshpack1.h"
Alexandre Julliardbf9130a1996-10-13 17:45:47 +000037
38 /* Hook data (pointed to by a HHOOK) */
39typedef struct
40{
41 HANDLE16 next; /* 00 Next hook in chain */
Ulrich Weigandf4edf231999-09-20 18:45:00 +000042 HOOKPROC proc; /* 02 Hook procedure (original) */
Alexandre Julliardbf9130a1996-10-13 17:45:47 +000043 INT16 id; /* 06 Hook id (WH_xxx) */
44 HQUEUE16 ownerQueue; /* 08 Owner queue (0 for system hook) */
45 HMODULE16 ownerModule; /* 0a Owner module */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000046 WORD flags; /* 0c flags */
Ulrich Weigandf4edf231999-09-20 18:45:00 +000047 HOOKPROC thunk; /* 0e Hook procedure (CallTo16 thunk) */
Alexandre Julliardbf9130a1996-10-13 17:45:47 +000048} HOOKDATA;
49
Patrik Stridvallc7a8dde1999-04-25 12:36:53 +000050#include "poppack.h"
Alexandre Julliardbf9130a1996-10-13 17:45:47 +000051
52#define HOOK_MAGIC ((int)'H' | (int)'K' << 8) /* 'HK' */
53
Alexandre Julliardade697e1995-11-26 13:59:11 +000054 /* This should probably reside in USER heap */
Alexandre Julliard3051b641996-07-05 17:14:13 +000055static HANDLE16 HOOK_systemHooks[WH_NB_HOOKS] = { 0, };
Alexandre Julliard58199531994-04-21 01:20:00 +000056
Alexandre Julliarda3960291999-02-26 11:11:13 +000057typedef VOID (*HOOK_MapFunc)(INT, INT, WPARAM *, LPARAM *);
58typedef VOID (*HOOK_UnMapFunc)(INT, INT, WPARAM, LPARAM, WPARAM,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000059 LPARAM);
60
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000061/***********************************************************************
62 * HOOK_Map16To32Common
63 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000064static void HOOK_Map16To32Common(INT id, INT code, WPARAM *pwParam,
65 LPARAM *plParam, BOOL bA )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000066{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000067
68 switch( id )
69 {
70 case WH_MSGFILTER:
71 case WH_SYSMSGFILTER:
72 case WH_GETMESSAGE:
73 case WH_JOURNALRECORD:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000074 {
Alexandre Julliard982a2232000-12-13 20:20:09 +000075 LPMSG16 lpmsg16 = MapSL(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +000076 LPMSG lpmsg32 = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpmsg32) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000077
78 STRUCT32_MSG16to32( lpmsg16, lpmsg32 );
79 *plParam = (LPARAM)lpmsg32;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000080 break;
81 }
82
83 case WH_JOURNALPLAYBACK:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000084 {
Alexandre Julliard982a2232000-12-13 20:20:09 +000085 LPEVENTMSG16 lpem16 = MapSL(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +000086 LPEVENTMSG lpem32 = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpem32) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000087
88 lpem32->message = lpem16->message;
89 lpem32->paramL = lpem16->paramL;
90 lpem32->paramH = lpem16->paramH;
91 lpem32->time = lpem16->time;
92 lpem32->hwnd = 0; /* FIXME */
93
94 *plParam = (LPARAM)lpem32;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000095 break;
96 }
97
98 case WH_CALLWNDPROC:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000099 {
Alexandre Julliard982a2232000-12-13 20:20:09 +0000100 LPCWPSTRUCT16 lpcwp16 = MapSL(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000101 LPCWPSTRUCT lpcwp32 = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpcwp32) );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000102
103 lpcwp32->hwnd = lpcwp16->hwnd;
104 lpcwp32->lParam = lpcwp16->lParam;
105
Alexandre Julliard77b99181997-09-14 17:17:23 +0000106 if (bA) WINPROC_MapMsg16To32A( lpcwp16->message, lpcwp16->wParam,
107 &lpcwp32->message, &lpcwp32->wParam,
108 &lpcwp32->lParam );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000109 else WINPROC_MapMsg16To32W( lpcwp16->hwnd,lpcwp16->message, lpcwp16->wParam,
Alexandre Julliard77b99181997-09-14 17:17:23 +0000110 &lpcwp32->message, &lpcwp32->wParam,
111 &lpcwp32->lParam );
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000112 *plParam = (LPARAM)lpcwp32;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000113 break;
114 }
115
116 case WH_CBT:
117 switch (code)
118 {
119 case HCBT_CREATEWND:
120 {
Alexandre Julliard982a2232000-12-13 20:20:09 +0000121 LPCBT_CREATEWND16 lpcbtcw16 = MapSL(*plParam);
122 LPCREATESTRUCT16 lpcs16 = MapSL((SEGPTR)lpcbtcw16->lpcs);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000123 LPCBT_CREATEWNDA lpcbtcw32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000124 sizeof(*lpcbtcw32) );
Alexandre Julliard90476d62000-02-16 22:47:24 +0000125 lpcbtcw32->lpcs = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000126 sizeof(*lpcbtcw32->lpcs) );
127
128 STRUCT32_CREATESTRUCT16to32A( lpcs16,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000129 (LPCREATESTRUCTA)lpcbtcw32->lpcs );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000130
131 if (HIWORD(lpcs16->lpszName))
132 lpcbtcw32->lpcs->lpszName =
Alexandre Julliard982a2232000-12-13 20:20:09 +0000133 (bA) ? MapSL(lpcs16->lpszName)
Alexandre Julliard90476d62000-02-16 22:47:24 +0000134 : HEAP_strdupAtoW( GetProcessHeap(), 0,
Alexandre Julliard982a2232000-12-13 20:20:09 +0000135 MapSL(lpcs16->lpszName) );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000136 else
137 lpcbtcw32->lpcs->lpszName = (LPCSTR)lpcs16->lpszName;
138
139 if (HIWORD(lpcs16->lpszClass))
140 lpcbtcw32->lpcs->lpszClass =
Alexandre Julliard982a2232000-12-13 20:20:09 +0000141 (bA) ? MapSL(lpcs16->lpszClass)
Alexandre Julliard90476d62000-02-16 22:47:24 +0000142 : HEAP_strdupAtoW( GetProcessHeap(), 0,
Alexandre Julliard982a2232000-12-13 20:20:09 +0000143 MapSL(lpcs16->lpszClass) );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000144 else
145 lpcbtcw32->lpcs->lpszClass = (LPCSTR)lpcs16->lpszClass;
146
147 lpcbtcw32->hwndInsertAfter = lpcbtcw16->hwndInsertAfter;
148
149 *plParam = (LPARAM)lpcbtcw32;
150 break;
151 }
152 case HCBT_ACTIVATE:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000153 {
Alexandre Julliard982a2232000-12-13 20:20:09 +0000154 LPCBTACTIVATESTRUCT16 lpcas16 = MapSL(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000155 LPCBTACTIVATESTRUCT lpcas32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000156 sizeof(*lpcas32) );
157 lpcas32->fMouse = lpcas16->fMouse;
158 lpcas32->hWndActive = lpcas16->hWndActive;
159 *plParam = (LPARAM)lpcas32;
160 break;
161 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000162 case HCBT_CLICKSKIPPED:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000163 {
Alexandre Julliard982a2232000-12-13 20:20:09 +0000164 LPMOUSEHOOKSTRUCT16 lpms16 = MapSL(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000165 LPMOUSEHOOKSTRUCT lpms32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000166 sizeof(*lpms32) );
167
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000168 CONV_POINT16TO32( &lpms16->pt, &lpms32->pt );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000169
170 /* wHitTestCode may be negative, so convince compiler to do
171 correct sign extension. Yay. :| */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000172 lpms32->wHitTestCode = (INT)((INT16)lpms16->wHitTestCode);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000173
174 lpms32->dwExtraInfo = lpms16->dwExtraInfo;
175 lpms32->hwnd = lpms16->hwnd;
176 *plParam = (LPARAM)lpms32;
177 break;
178 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000179 case HCBT_MOVESIZE:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000180 {
Alexandre Julliard982a2232000-12-13 20:20:09 +0000181 LPRECT16 lprect16 = MapSL(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000182 LPRECT lprect32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000183 sizeof(*lprect32) );
184
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000185 CONV_RECT16TO32( lprect16, lprect32 );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000186 *plParam = (LPARAM)lprect32;
187 break;
188 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000189 }
Alexandre Julliard21979011997-03-05 08:22:35 +0000190 break;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000191
192 case WH_MOUSE:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000193 {
Alexandre Julliard982a2232000-12-13 20:20:09 +0000194 LPMOUSEHOOKSTRUCT16 lpms16 = MapSL(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000195 LPMOUSEHOOKSTRUCT lpms32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000196 sizeof(*lpms32) );
197
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000198 CONV_POINT16TO32( &lpms16->pt, &lpms32->pt );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000199
200 /* wHitTestCode may be negative, so convince compiler to do
201 correct sign extension. Yay. :| */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000202 lpms32->wHitTestCode = (INT)((INT16)lpms16->wHitTestCode);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000203 lpms32->dwExtraInfo = lpms16->dwExtraInfo;
204 lpms32->hwnd = lpms16->hwnd;
205 *plParam = (LPARAM)lpms32;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000206 break;
207 }
208
209 case WH_DEBUG:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000210 {
Alexandre Julliard982a2232000-12-13 20:20:09 +0000211 LPDEBUGHOOKINFO16 lpdh16 = MapSL(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000212 LPDEBUGHOOKINFO lpdh32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000213 sizeof(*lpdh32) );
214
215 lpdh32->idThread = 0; /* FIXME */
216 lpdh32->idThreadInstaller = 0; /* FIXME */
217 lpdh32->lParam = lpdh16->lParam; /* FIXME Check for sign ext */
218 lpdh32->wParam = lpdh16->wParam;
219 lpdh32->code = lpdh16->code;
220
221 /* do sign extension if it was WH_MSGFILTER */
222 if (*pwParam == 0xffff) *pwParam = WH_MSGFILTER;
223
224 *plParam = (LPARAM)lpdh32;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000225 break;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000226 }
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000227
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000228 case WH_SHELL:
229 case WH_KEYBOARD:
230 break;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000231
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000232 case WH_HARDWARE:
233 case WH_FOREGROUNDIDLE:
234 case WH_CALLWNDPROCRET:
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000235 FIXME("\t[%i] 16to32 translation unimplemented\n", id);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000236 }
237}
238
239
240/***********************************************************************
241 * HOOK_Map16To32A
242 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000243static void HOOK_Map16To32A(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000244 LPARAM *plParam)
245{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000246 HOOK_Map16To32Common( id, code, pwParam, plParam, TRUE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000247}
248
249
250/***********************************************************************
251 * HOOK_Map16To32W
252 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000253static void HOOK_Map16To32W(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000254 LPARAM *plParam)
255{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000256 HOOK_Map16To32Common( id, code, pwParam, plParam, FALSE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000257}
258
259
260/***********************************************************************
261 * HOOK_UnMap16To32Common
262 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000263static void HOOK_UnMap16To32Common(INT id, INT code, WPARAM wParamOrig,
264 LPARAM lParamOrig, WPARAM wParam,
265 LPARAM lParam, BOOL bA)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000266{
267 switch (id)
268 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000269 case WH_MSGFILTER:
270 case WH_SYSMSGFILTER:
271 case WH_JOURNALRECORD:
272 case WH_JOURNALPLAYBACK:
273
Alexandre Julliard90476d62000-02-16 22:47:24 +0000274 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000275 break;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000276
277 case WH_CALLWNDPROC:
278 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000279 LPCWPSTRUCT lpcwp32 = (LPCWPSTRUCT)lParam;
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000280 if (bA) WINPROC_UnmapMsg16To32A( lpcwp32->hwnd,lpcwp32->message, lpcwp32->wParam,
Alexandre Julliard491502b1997-11-01 19:08:16 +0000281 lpcwp32->lParam, 0 );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000282 else WINPROC_UnmapMsg16To32W( lpcwp32->hwnd,lpcwp32->message, lpcwp32->wParam,
Alexandre Julliard491502b1997-11-01 19:08:16 +0000283 lpcwp32->lParam, 0 );
Alexandre Julliard90476d62000-02-16 22:47:24 +0000284 HeapFree( GetProcessHeap(), 0, lpcwp32 );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000285 break;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000286 }
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000287
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000288 case WH_GETMESSAGE:
289 {
Alexandre Julliard982a2232000-12-13 20:20:09 +0000290 LPMSG16 lpmsg16 = MapSL(lParamOrig);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000291 STRUCT32_MSG32to16( (LPMSG)lParam, lpmsg16 );
Alexandre Julliard90476d62000-02-16 22:47:24 +0000292 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000293 break;
294 }
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000295
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000296 case WH_MOUSE:
297 case WH_DEBUG:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000298
Alexandre Julliard90476d62000-02-16 22:47:24 +0000299 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000300 break;
301
302 case WH_CBT:
303 switch (code)
304 {
305 case HCBT_CREATEWND:
306 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000307 LPCBT_CREATEWNDA lpcbtcw32 = (LPCBT_CREATEWNDA)lParam;
Alexandre Julliard982a2232000-12-13 20:20:09 +0000308 LPCBT_CREATEWND16 lpcbtcw16 = MapSL(lParamOrig);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000309
310 if( !bA )
311 {
312 if (HIWORD(lpcbtcw32->lpcs->lpszName))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000313 HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcw32->lpcs->lpszName );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000314 if (HIWORD(lpcbtcw32->lpcs->lpszClass))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000315 HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcw32->lpcs->lpszClass );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000316 }
317
318 lpcbtcw16->hwndInsertAfter = lpcbtcw32->hwndInsertAfter;
319
Alexandre Julliard90476d62000-02-16 22:47:24 +0000320 HeapFree( GetProcessHeap(), 0, lpcbtcw32->lpcs );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000321 } /* fall through */
322
323 case HCBT_ACTIVATE:
324 case HCBT_CLICKSKIPPED:
325 case HCBT_MOVESIZE:
326
Alexandre Julliard90476d62000-02-16 22:47:24 +0000327 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000328 break;
329 }
330 break;
331
332 case WH_SHELL:
333 case WH_KEYBOARD:
334 break;
335
336 case WH_HARDWARE:
337 case WH_FOREGROUNDIDLE:
338 case WH_CALLWNDPROCRET:
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000339 FIXME("\t[%i] skipping unmap\n", id);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000340 break;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000341 }
342}
343
344
345/***********************************************************************
346 * HOOK_UnMap16To32A
347 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000348static void HOOK_UnMap16To32A(INT id, INT code, WPARAM wParamOrig,
349 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000350 LPARAM lParam)
351{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000352 HOOK_UnMap16To32Common( id, code, wParamOrig, lParamOrig, wParam,
353 lParam, TRUE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000354}
355
356
357/***********************************************************************
358 * HOOK_UnMap16To32W
359 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000360static void HOOK_UnMap16To32W(INT id, INT code, WPARAM wParamOrig,
361 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000362 LPARAM lParam)
363{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000364 HOOK_UnMap16To32Common( id, code, wParamOrig, lParamOrig, wParam,
365 lParam, FALSE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000366}
367
368
369/***********************************************************************
370 * HOOK_Map32To16Common
371 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000372static void HOOK_Map32To16Common(INT id, INT code, WPARAM *pwParam,
373 LPARAM *plParam, BOOL bA)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000374{
375 switch (id)
376 {
377 case WH_MSGFILTER:
378 case WH_SYSMSGFILTER:
379 case WH_GETMESSAGE:
380 case WH_JOURNALRECORD:
381 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000382 LPMSG lpmsg32 = (LPMSG)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000383 LPMSG16 lpmsg16 = SEGPTR_NEW( MSG16 );
384
385 STRUCT32_MSG32to16( lpmsg32, lpmsg16 );
386
387 *plParam = (LPARAM)SEGPTR_GET( lpmsg16 );
388 break;
389 }
390
391 case WH_JOURNALPLAYBACK:
392 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000393 LPEVENTMSG lpem32 = (LPEVENTMSG)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000394 LPEVENTMSG16 lpem16 = SEGPTR_NEW( EVENTMSG16 );
395
396 lpem16->message = lpem32->message;
397 lpem16->paramL = lpem32->paramL;
398 lpem16->paramH = lpem32->paramH;
399 lpem16->time = lpem32->time;
400
401 *plParam = (LPARAM)SEGPTR_GET( lpem16 );
402 break;
403 }
404
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000405 case WH_CALLWNDPROC:
406 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000407 LPCWPSTRUCT lpcwp32 = (LPCWPSTRUCT)*plParam;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000408 LPCWPSTRUCT16 lpcwp16 = SEGPTR_NEW( CWPSTRUCT16 );
409
410 lpcwp16->hwnd = lpcwp32->hwnd;
411 lpcwp16->lParam = lpcwp32->lParam;
412
Alexandre Julliard491502b1997-11-01 19:08:16 +0000413 if (bA) WINPROC_MapMsg32ATo16( lpcwp32->hwnd, lpcwp32->message,
414 lpcwp32->wParam, &lpcwp16->message,
415 &lpcwp16->wParam, &lpcwp16->lParam );
416 else WINPROC_MapMsg32WTo16( lpcwp32->hwnd, lpcwp32->message,
417 lpcwp32->wParam, &lpcwp16->message,
418 &lpcwp16->wParam, &lpcwp16->lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000419 *plParam = (LPARAM)SEGPTR_GET( lpcwp16 );
420 break;
421 }
422
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000423 case WH_CBT:
424 switch (code)
425 {
426 case HCBT_ACTIVATE:
427 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000428 LPCBTACTIVATESTRUCT lpcas32 = (LPCBTACTIVATESTRUCT)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000429 LPCBTACTIVATESTRUCT16 lpcas16 =SEGPTR_NEW( CBTACTIVATESTRUCT16 );
430
431 lpcas16->fMouse = lpcas32->fMouse;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000432 lpcas16->hWndActive = lpcas32->hWndActive;
433
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000434 *plParam = (LPARAM)SEGPTR_GET( lpcas16 );
435 break;
436 }
437
438 case HCBT_CLICKSKIPPED:
439 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000440 LPMOUSEHOOKSTRUCT lpms32 = (LPMOUSEHOOKSTRUCT)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000441 LPMOUSEHOOKSTRUCT16 lpms16 = SEGPTR_NEW( MOUSEHOOKSTRUCT16 );
442
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000443 CONV_POINT32TO16( &lpms32->pt, &lpms16->pt );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000444
445 lpms16->hwnd = lpms32->hwnd;
446 lpms16->wHitTestCode = lpms32->wHitTestCode;
447 lpms16->dwExtraInfo = lpms32->dwExtraInfo;
448
449 *plParam = (LPARAM)SEGPTR_GET( lpms16 );
450 break;
451 }
452
453 case HCBT_MOVESIZE:
454 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000455 LPRECT lprect32 = (LPRECT)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000456 LPRECT16 lprect16 = SEGPTR_NEW( RECT16 );
457
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000458 CONV_RECT32TO16( lprect32, lprect16 );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000459
460 *plParam = (LPARAM)SEGPTR_GET( lprect16 );
461 break;
462 }
463 }
464 break;
465
466 case WH_MOUSE:
467 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000468 LPMOUSEHOOKSTRUCT lpms32 = (LPMOUSEHOOKSTRUCT)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000469 LPMOUSEHOOKSTRUCT16 lpms16 = SEGPTR_NEW( MOUSEHOOKSTRUCT16 );
470
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000471 CONV_POINT32TO16( &lpms32->pt, &lpms16->pt );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000472
473 lpms16->hwnd = lpms32->hwnd;
474 lpms16->wHitTestCode = lpms32->wHitTestCode;
475 lpms16->dwExtraInfo = lpms32->dwExtraInfo;
476
477 *plParam = (LPARAM)SEGPTR_GET( lpms16 );
478 break;
479 }
480
481 case WH_DEBUG:
482 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000483 LPDEBUGHOOKINFO lpdh32 = (LPDEBUGHOOKINFO)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000484 LPDEBUGHOOKINFO16 lpdh16 = SEGPTR_NEW( DEBUGHOOKINFO16 );
485
486 lpdh16->hModuleHook = 0; /* FIXME */
487 lpdh16->reserved = 0;
488 lpdh16->lParam = lpdh32->lParam;
489 lpdh16->wParam = lpdh32->wParam;
490 lpdh16->code = lpdh32->code;
491
492 *plParam = (LPARAM)SEGPTR_GET( lpdh16 );
493 break;
494 }
495
496 case WH_SHELL:
497 case WH_KEYBOARD:
498 break;
499
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000500 case WH_HARDWARE:
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000501 case WH_FOREGROUNDIDLE:
502 case WH_CALLWNDPROCRET:
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000503 FIXME("\t[%i] 32to16 translation unimplemented\n", id);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000504 }
505}
506
507
508/***********************************************************************
509 * HOOK_Map32ATo16
510 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000511static void HOOK_Map32ATo16(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000512 LPARAM *plParam)
513{
514 if (id == WH_CBT && code == HCBT_CREATEWND)
515 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000516 LPCBT_CREATEWNDA lpcbtcw32 = (LPCBT_CREATEWNDA)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000517 LPCBT_CREATEWND16 lpcbtcw16 = SEGPTR_NEW( CBT_CREATEWND16 );
518 LPCREATESTRUCT16 lpcs16 = SEGPTR_NEW( CREATESTRUCT16 );
519
520 lpcbtcw16->lpcs = (LPCREATESTRUCT16)SEGPTR_GET( lpcs16 );
521 STRUCT32_CREATESTRUCT32Ato16( lpcbtcw32->lpcs, lpcs16 );
522
523 if (HIWORD(lpcbtcw32->lpcs->lpszName))
524 lpcs16->lpszName =
525 SEGPTR_GET( SEGPTR_STRDUP( lpcbtcw32->lpcs->lpszName ) );
526 else
527 lpcs16->lpszName = (SEGPTR)lpcbtcw32->lpcs->lpszName;
528
529 if (HIWORD(lpcbtcw32->lpcs->lpszClass))
530 lpcs16->lpszClass =
531 SEGPTR_GET( SEGPTR_STRDUP( lpcbtcw32->lpcs->lpszClass ) );
532 else
533 lpcs16->lpszClass = (SEGPTR)lpcbtcw32->lpcs->lpszClass;
534
535 lpcbtcw16->hwndInsertAfter = lpcbtcw32->hwndInsertAfter;
536
537 *plParam = (LPARAM)SEGPTR_GET( lpcbtcw16 );
538 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000539 else HOOK_Map32To16Common(id, code, pwParam, plParam, TRUE);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000540}
541
542
543/***********************************************************************
544 * HOOK_Map32WTo16
545 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000546static void HOOK_Map32WTo16(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000547 LPARAM *plParam)
548{
549 if (id == WH_CBT && code == HCBT_CREATEWND)
550 {
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000551 LPSTR name, cls;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000552 LPCBT_CREATEWNDW lpcbtcw32 = (LPCBT_CREATEWNDW)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000553 LPCBT_CREATEWND16 lpcbtcw16 = SEGPTR_NEW( CBT_CREATEWND16 );
554 LPCREATESTRUCT16 lpcs16 = SEGPTR_NEW( CREATESTRUCT16 );
555
556 lpcbtcw16->lpcs = (LPCREATESTRUCT16)SEGPTR_GET( lpcs16 );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000557 STRUCT32_CREATESTRUCT32Ato16( (LPCREATESTRUCTA)lpcbtcw32->lpcs,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000558 lpcs16 );
559
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000560 name = SEGPTR_STRDUP_WtoA( lpcbtcw32->lpcs->lpszName );
561 cls = SEGPTR_STRDUP_WtoA( lpcbtcw32->lpcs->lpszClass );
562 lpcs16->lpszName = SEGPTR_GET( name );
563 lpcs16->lpszClass = SEGPTR_GET( cls );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000564 lpcbtcw16->hwndInsertAfter = lpcbtcw32->hwndInsertAfter;
565
566 *plParam = (LPARAM)SEGPTR_GET( lpcbtcw16 );
567 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000568 else HOOK_Map32To16Common(id, code, pwParam, plParam, FALSE);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000569}
570
571
572/***********************************************************************
573 * HOOK_UnMap32To16Common
574 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000575static void HOOK_UnMap32To16Common(INT id, INT code, WPARAM wParamOrig,
576 LPARAM lParamOrig, WPARAM wParam,
577 LPARAM lParam, BOOL bA)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000578{
579 switch (id)
580 {
581 case WH_MSGFILTER:
582 case WH_SYSMSGFILTER:
583 case WH_JOURNALRECORD:
584 case WH_JOURNALPLAYBACK:
585 case WH_MOUSE:
586 case WH_DEBUG:
Alexandre Julliard982a2232000-12-13 20:20:09 +0000587 SEGPTR_FREE( MapSL(lParam) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000588 break;
589
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000590 case WH_CALLWNDPROC:
591 {
Alexandre Julliard982a2232000-12-13 20:20:09 +0000592 LPCWPSTRUCT16 lpcwp16 = MapSL(lParam);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000593 LPCWPSTRUCT lpcwp32 = (LPCWPSTRUCT)lParamOrig;
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +0000594 MSGPARAM16 mp16;
595
596 mp16.wParam = lpcwp16->wParam;
597 mp16.lParam = lpcwp16->lParam;
598 mp16.lResult = 0;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000599
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000600 if (bA) WINPROC_UnmapMsg32ATo16( lpcwp32->hwnd,lpcwp32->message, lpcwp32->wParam,
Alexandre Julliard77b99181997-09-14 17:17:23 +0000601 lpcwp32->lParam, &mp16 );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000602 else WINPROC_UnmapMsg32WTo16( lpcwp32->hwnd,lpcwp32->message, lpcwp32->wParam,
Alexandre Julliard77b99181997-09-14 17:17:23 +0000603 lpcwp32->lParam, &mp16 );
Alexandre Julliard982a2232000-12-13 20:20:09 +0000604 SEGPTR_FREE( MapSL(lParam) );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000605 break;
606 }
607
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000608 case WH_GETMESSAGE:
609 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000610 LPMSG lpmsg32 = (LPMSG)lParamOrig;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000611
Alexandre Julliard982a2232000-12-13 20:20:09 +0000612 STRUCT32_MSG16to32( MapSL(lParam), lpmsg32 );
613 SEGPTR_FREE( MapSL(lParam) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000614 break;
615 }
616
617 case WH_CBT:
618 switch (code)
619 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000620 case HCBT_CREATEWND:
621 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000622 LPCBT_CREATEWNDA lpcbtcw32 = (LPCBT_CREATEWNDA)(lParamOrig);
Alexandre Julliard982a2232000-12-13 20:20:09 +0000623 LPCBT_CREATEWND16 lpcbtcw16 = MapSL(lParam);
624 LPCREATESTRUCT16 lpcs16 = MapSL((SEGPTR)lpcbtcw16->lpcs);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000625
626 if (HIWORD(lpcs16->lpszName))
Alexandre Julliard982a2232000-12-13 20:20:09 +0000627 SEGPTR_FREE( MapSL(lpcs16->lpszName) );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000628
629 if (HIWORD(lpcs16->lpszClass))
Alexandre Julliard982a2232000-12-13 20:20:09 +0000630 SEGPTR_FREE( MapSL(lpcs16->lpszClass) );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000631
632 lpcbtcw32->hwndInsertAfter = lpcbtcw16->hwndInsertAfter;
633
634 SEGPTR_FREE( lpcs16 );
635 } /* fall through */
636
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000637 case HCBT_ACTIVATE:
638 case HCBT_CLICKSKIPPED:
639 case HCBT_MOVESIZE:
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000640
Alexandre Julliard982a2232000-12-13 20:20:09 +0000641 SEGPTR_FREE( MapSL(lParam) );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000642 break;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000643 }
644 break;
645
646 case WH_SHELL:
647 case WH_KEYBOARD:
648 break;
649
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000650 case WH_HARDWARE:
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000651 case WH_FOREGROUNDIDLE:
652 case WH_CALLWNDPROCRET:
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000653 FIXME("\t[%i] skipping unmap\n", id);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000654 }
655}
656
657
658/***********************************************************************
659 * HOOK_UnMap32ATo16
660 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000661static void HOOK_UnMap32ATo16(INT id, INT code, WPARAM wParamOrig,
662 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000663 LPARAM lParam)
664{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000665 HOOK_UnMap32To16Common( id, code, wParamOrig, lParamOrig, wParam,
666 lParam, TRUE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000667}
668
669
670/***********************************************************************
671 * HOOK_UnMap32WTo16
672 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000673static void HOOK_UnMap32WTo16(INT id, INT code, WPARAM wParamOrig,
674 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000675 LPARAM lParam)
676{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000677 HOOK_UnMap32To16Common( id, code, wParamOrig, lParamOrig, wParam,
678 lParam, FALSE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000679}
680
681
682/***********************************************************************
683 * HOOK_Map32ATo32W
684 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000685static void HOOK_Map32ATo32W(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000686 LPARAM *plParam)
687{
688 if (id == WH_CBT && code == HCBT_CREATEWND)
689 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000690 LPCBT_CREATEWNDA lpcbtcwA = (LPCBT_CREATEWNDA)*plParam;
Alexandre Julliard90476d62000-02-16 22:47:24 +0000691 LPCBT_CREATEWNDW lpcbtcwW = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000692 sizeof(*lpcbtcwW) );
Alexandre Julliard90476d62000-02-16 22:47:24 +0000693 lpcbtcwW->lpcs = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpcbtcwW->lpcs) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000694
695 lpcbtcwW->hwndInsertAfter = lpcbtcwA->hwndInsertAfter;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000696 *lpcbtcwW->lpcs = *(LPCREATESTRUCTW)lpcbtcwA->lpcs;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000697
698 if (HIWORD(lpcbtcwA->lpcs->lpszName))
699 {
Alexandre Julliard90476d62000-02-16 22:47:24 +0000700 lpcbtcwW->lpcs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000701 lpcbtcwA->lpcs->lpszName );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000702 }
703 else
704 lpcbtcwW->lpcs->lpszName = (LPWSTR)lpcbtcwA->lpcs->lpszName;
705
706 if (HIWORD(lpcbtcwA->lpcs->lpszClass))
707 {
Alexandre Julliard90476d62000-02-16 22:47:24 +0000708 lpcbtcwW->lpcs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000709 lpcbtcwA->lpcs->lpszClass );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000710 }
711 else
712 lpcbtcwW->lpcs->lpszClass = (LPCWSTR)lpcbtcwA->lpcs->lpszClass;
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000713 *plParam = (LPARAM)lpcbtcwW;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000714 }
715 return;
716}
717
718
719/***********************************************************************
720 * HOOK_UnMap32ATo32W
721 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000722static void HOOK_UnMap32ATo32W(INT id, INT code, WPARAM wParamOrig,
723 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000724 LPARAM lParam)
725{
726 if (id == WH_CBT && code == HCBT_CREATEWND)
727 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000728 LPCBT_CREATEWNDW lpcbtcwW = (LPCBT_CREATEWNDW)lParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000729 if (HIWORD(lpcbtcwW->lpcs->lpszName))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000730 HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcwW->lpcs->lpszName );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000731 if (HIWORD(lpcbtcwW->lpcs->lpszClass))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000732 HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcwW->lpcs->lpszClass );
733 HeapFree( GetProcessHeap(), 0, lpcbtcwW->lpcs );
734 HeapFree( GetProcessHeap(), 0, lpcbtcwW );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000735 }
736 return;
737}
738
739
740/***********************************************************************
741 * HOOK_Map32WTo32A
742 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000743static void HOOK_Map32WTo32A(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000744 LPARAM *plParam)
745{
746 if (id == WH_CBT && code == HCBT_CREATEWND)
747 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000748 LPCBT_CREATEWNDW lpcbtcwW = (LPCBT_CREATEWNDW)*plParam;
Alexandre Julliard90476d62000-02-16 22:47:24 +0000749 LPCBT_CREATEWNDA lpcbtcwA = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000750 sizeof(*lpcbtcwA) );
Alexandre Julliard90476d62000-02-16 22:47:24 +0000751 lpcbtcwA->lpcs = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpcbtcwA->lpcs) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000752
753 lpcbtcwA->hwndInsertAfter = lpcbtcwW->hwndInsertAfter;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000754 *lpcbtcwA->lpcs = *(LPCREATESTRUCTA)lpcbtcwW->lpcs;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000755
756 if (HIWORD(lpcbtcwW->lpcs->lpszName))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000757 lpcbtcwA->lpcs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000758 lpcbtcwW->lpcs->lpszName );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000759 else
760 lpcbtcwA->lpcs->lpszName = (LPSTR)lpcbtcwW->lpcs->lpszName;
761
762 if (HIWORD(lpcbtcwW->lpcs->lpszClass))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000763 lpcbtcwA->lpcs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000764 lpcbtcwW->lpcs->lpszClass );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000765 else
766 lpcbtcwA->lpcs->lpszClass = (LPSTR)lpcbtcwW->lpcs->lpszClass;
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000767 *plParam = (LPARAM)lpcbtcwA;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000768 }
769 return;
770}
771
772
773/***********************************************************************
774 * HOOK_UnMap32WTo32A
775 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000776static void HOOK_UnMap32WTo32A(INT id, INT code, WPARAM wParamOrig,
777 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000778 LPARAM lParam)
779{
780 if (id == WH_CBT && code == HCBT_CREATEWND)
781 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000782 LPCBT_CREATEWNDA lpcbtcwA = (LPCBT_CREATEWNDA)lParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000783 if (HIWORD(lpcbtcwA->lpcs->lpszName))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000784 HeapFree( GetProcessHeap(), 0, (LPSTR)lpcbtcwA->lpcs->lpszName );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000785 if (HIWORD(lpcbtcwA->lpcs->lpszClass))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000786 HeapFree( GetProcessHeap(), 0, (LPSTR)lpcbtcwA->lpcs->lpszClass );
787 HeapFree( GetProcessHeap(), 0, lpcbtcwA->lpcs );
788 HeapFree( GetProcessHeap(), 0, lpcbtcwA );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000789 }
790 return;
791}
792
793
794/***********************************************************************
795 * Map Function Tables
796 */
797static const HOOK_MapFunc HOOK_MapFuncs[3][3] =
798{
799 { NULL, HOOK_Map16To32A, HOOK_Map16To32W },
800 { HOOK_Map32ATo16, NULL, HOOK_Map32ATo32W },
801 { HOOK_Map32WTo16, HOOK_Map32WTo32A, NULL }
802};
803
804static const HOOK_UnMapFunc HOOK_UnMapFuncs[3][3] =
805{
806 { NULL, HOOK_UnMap16To32A, HOOK_UnMap16To32W },
807 { HOOK_UnMap32ATo16, NULL, HOOK_UnMap32ATo32W },
808 { HOOK_UnMap32WTo16, HOOK_UnMap32WTo32A, NULL }
809};
810
811
812/***********************************************************************
813 * Internal Functions
814 */
Alexandre Julliard58199531994-04-21 01:20:00 +0000815
Alexandre Julliardade697e1995-11-26 13:59:11 +0000816/***********************************************************************
817 * HOOK_GetNextHook
818 *
819 * Get the next hook of a given hook.
820 */
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000821static HANDLE16 HOOK_GetNextHook( HANDLE16 hook )
Alexandre Julliardade697e1995-11-26 13:59:11 +0000822{
823 HOOKDATA *data = (HOOKDATA *)USER_HEAP_LIN_ADDR( hook );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000824
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000825 if (!data || !hook) return 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000826 if (data->next) return data->next;
827 if (!data->ownerQueue) return 0; /* Already system hook */
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000828
Alexandre Julliardade697e1995-11-26 13:59:11 +0000829 /* Now start enumerating the system hooks */
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000830 return HOOK_systemHooks[data->id - WH_MINHOOK];
Alexandre Julliardade697e1995-11-26 13:59:11 +0000831}
832
833
834/***********************************************************************
835 * HOOK_GetHook
836 *
837 * Get the first hook for a given type.
838 */
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000839static HANDLE16 HOOK_GetHook( INT16 id, HQUEUE16 hQueue )
Alexandre Julliardade697e1995-11-26 13:59:11 +0000840{
841 MESSAGEQUEUE *queue;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000842 HANDLE16 hook = 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000843
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000844 if ((queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue )) != NULL)
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000845 hook = queue->hooks[id - WH_MINHOOK];
846 if (!hook) hook = HOOK_systemHooks[id - WH_MINHOOK];
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000847
848 QUEUE_Unlock( queue );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000849 return hook;
850}
851
852
853/***********************************************************************
854 * HOOK_SetHook
855 *
856 * Install a given hook.
857 */
Ulrich Weigandf4edf231999-09-20 18:45:00 +0000858/* ### start build ### */
859extern LONG CALLBACK HOOK_CallTo16_long_wwl(FARPROC16,WORD,WORD,LONG);
860/* ### stop build ### */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000861static HHOOK HOOK_SetHook( INT16 id, LPVOID proc, INT type,
Ulrich Weiganda8975181999-01-20 13:11:45 +0000862 HMODULE16 hModule, DWORD dwThreadId )
Alexandre Julliardade697e1995-11-26 13:59:11 +0000863{
864 HOOKDATA *data;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000865 HANDLE16 handle;
866 HQUEUE16 hQueue = 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000867
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000868 if ((id < WH_MINHOOK) || (id > WH_MAXHOOK)) return 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000869
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000870 TRACE("Setting hook %d: %08x %04x %08lx\n",
Alexandre Julliarda3960291999-02-26 11:11:13 +0000871 id, (UINT)proc, hModule, dwThreadId );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000872
Ulrich Weiganda8975181999-01-20 13:11:45 +0000873 /* Create task queue if none present */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000874 GetFastQueue16();
Alexandre Julliard77b99181997-09-14 17:17:23 +0000875
Alexandre Julliarda3960291999-02-26 11:11:13 +0000876 if (id == WH_JOURNALPLAYBACK) EnableHardwareInput16(FALSE);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000877
Ulrich Weiganda8975181999-01-20 13:11:45 +0000878 if (dwThreadId) /* Task-specific hook */
Alexandre Julliardade697e1995-11-26 13:59:11 +0000879 {
880 if ((id == WH_JOURNALRECORD) || (id == WH_JOURNALPLAYBACK) ||
881 (id == WH_SYSMSGFILTER)) return 0; /* System-only hooks */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000882 if (!(hQueue = GetThreadQueue16( dwThreadId )))
Ulrich Weiganda8975181999-01-20 13:11:45 +0000883 return 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000884 }
885
Alexandre Julliardade697e1995-11-26 13:59:11 +0000886 /* Create the hook structure */
887
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000888 if (!(handle = USER_HEAP_ALLOC( sizeof(HOOKDATA) ))) return 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000889 data = (HOOKDATA *) USER_HEAP_LIN_ADDR( handle );
890 data->proc = proc;
891 data->id = id;
892 data->ownerQueue = hQueue;
Ulrich Weiganda8975181999-01-20 13:11:45 +0000893 data->ownerModule = hModule;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000894 data->flags = type;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000895
Ulrich Weigandf4edf231999-09-20 18:45:00 +0000896 /* Create CallTo16 thunk for 16-bit hooks */
897
898 if ( (data->flags & HOOK_MAPTYPE) == HOOK_WIN16 )
899 data->thunk = (HOOKPROC)THUNK_Alloc( (FARPROC16)data->proc,
900 (RELAY)HOOK_CallTo16_long_wwl );
901 else
902 data->thunk = data->proc;
903
904 if ( !data->thunk && data->proc )
905 {
906 USER_HEAP_FREE( handle );
907 return 0;
908 }
909
Alexandre Julliardade697e1995-11-26 13:59:11 +0000910 /* Insert it in the correct linked list */
911
912 if (hQueue)
913 {
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000914 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000915 data->next = queue->hooks[id - WH_MINHOOK];
916 queue->hooks[id - WH_MINHOOK] = handle;
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000917 QUEUE_Unlock( queue );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000918 }
919 else
920 {
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000921 data->next = HOOK_systemHooks[id - WH_MINHOOK];
922 HOOK_systemHooks[id - WH_MINHOOK] = handle;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000923 }
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000924 TRACE("Setting hook %d: ret=%04x [next=%04x]\n",
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000925 id, handle, data->next );
Ulrich Weiganda8975181999-01-20 13:11:45 +0000926
927 return (HHOOK)( handle? MAKELONG( handle, HOOK_MAGIC ) : 0 );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000928}
929
930
931/***********************************************************************
932 * HOOK_RemoveHook
933 *
934 * Remove a hook from the list.
935 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000936static BOOL HOOK_RemoveHook( HANDLE16 hook )
Alexandre Julliardade697e1995-11-26 13:59:11 +0000937{
938 HOOKDATA *data;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000939 HANDLE16 *prevHook;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000940
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000941 TRACE("Removing hook %04x\n", hook );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000942
943 if (!(data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook))) return FALSE;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000944 if (data->flags & HOOK_INUSE)
Alexandre Julliardade697e1995-11-26 13:59:11 +0000945 {
946 /* Mark it for deletion later on */
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000947 WARN("Hook still running, deletion delayed\n" );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000948 data->proc = (HOOKPROC)0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000949 return TRUE;
950 }
951
Alexandre Julliarda3960291999-02-26 11:11:13 +0000952 if (data->id == WH_JOURNALPLAYBACK) EnableHardwareInput16(TRUE);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000953
Alexandre Julliardade697e1995-11-26 13:59:11 +0000954 /* Remove it from the linked list */
955
956 if (data->ownerQueue)
957 {
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000958 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( data->ownerQueue );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000959 if (!queue) return FALSE;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000960 prevHook = &queue->hooks[data->id - WH_MINHOOK];
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000961 QUEUE_Unlock( queue );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000962 }
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000963 else prevHook = &HOOK_systemHooks[data->id - WH_MINHOOK];
Alexandre Julliardade697e1995-11-26 13:59:11 +0000964
965 while (*prevHook && *prevHook != hook)
966 prevHook = &((HOOKDATA *)USER_HEAP_LIN_ADDR(*prevHook))->next;
967
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000968 if (!*prevHook) return FALSE;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000969 *prevHook = data->next;
Ulrich Weigandf4edf231999-09-20 18:45:00 +0000970
971 if ( (data->flags & HOOK_MAPTYPE) == HOOK_WIN16 )
972 THUNK_Free( (FARPROC)data->thunk );
973
Alexandre Julliardade697e1995-11-26 13:59:11 +0000974 USER_HEAP_FREE( hook );
975 return TRUE;
976}
977
978
979/***********************************************************************
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000980 * HOOK_FindValidHook
981 */
982static HANDLE16 HOOK_FindValidHook( HANDLE16 hook )
983{
984 HOOKDATA *data;
985
986 for (;;)
987 {
988 if (!(data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook))) return 0;
989 if (data->proc) return hook;
990 hook = data->next;
991 }
992}
993
994
995/***********************************************************************
Alexandre Julliardade697e1995-11-26 13:59:11 +0000996 * HOOK_CallHook
997 *
998 * Call a hook procedure.
999 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001000static LRESULT HOOK_CallHook( HANDLE16 hook, INT fromtype, INT code,
1001 WPARAM wParam, LPARAM lParam )
Alexandre Julliardade697e1995-11-26 13:59:11 +00001002{
Alexandre Julliardade697e1995-11-26 13:59:11 +00001003 MESSAGEQUEUE *queue;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001004 HANDLE16 prevHook;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001005 HOOKDATA *data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook);
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001006 LRESULT ret;
Ulrich Weigand4b6b1c31999-05-17 14:55:30 +00001007 int iWndsLocks;
Alexandre Julliardade697e1995-11-26 13:59:11 +00001008
Alexandre Julliarda3960291999-02-26 11:11:13 +00001009 WPARAM wParamOrig = wParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001010 LPARAM lParamOrig = lParam;
1011 HOOK_MapFunc MapFunc;
1012 HOOK_UnMapFunc UnMapFunc;
Alexandre Julliardade697e1995-11-26 13:59:11 +00001013
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001014 MapFunc = HOOK_MapFuncs[fromtype][data->flags & HOOK_MAPTYPE];
1015 UnMapFunc = HOOK_UnMapFuncs[fromtype][data->flags & HOOK_MAPTYPE];
1016
1017 if (MapFunc)
1018 MapFunc( data->id, code, &wParam, &lParam );
Alexandre Julliardade697e1995-11-26 13:59:11 +00001019
1020 /* Now call it */
1021
Alexandre Julliarda3960291999-02-26 11:11:13 +00001022 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +00001023 prevHook = queue->hCurHook;
1024 queue->hCurHook = hook;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001025 data->flags |= HOOK_INUSE;
Alexandre Julliardade697e1995-11-26 13:59:11 +00001026
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001027 TRACE("Calling hook %04x: %d %08x %08lx\n",
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001028 hook, code, wParam, lParam );
1029
Ulrich Weigand4b6b1c31999-05-17 14:55:30 +00001030 /* Suspend window structure locks before calling user code */
1031 iWndsLocks = WIN_SuspendWndsLock();
1032
Ulrich Weigandf4edf231999-09-20 18:45:00 +00001033 ret = data->thunk(code, wParam, lParam);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001034
Ulrich Weigand5b803351999-03-16 10:29:55 +00001035 /* Grrr. While the hook procedure is supposed to have an LRESULT return
1036 value even in Win16, it seems that for those hook types where the
1037 return value is interpreted as BOOL, Windows doesn't actually check
1038 the HIWORD ... Some buggy Win16 programs, notably WINFILE, rely on
1039 that, because they neglect to clear DX ... */
1040 if ( (data->flags & HOOK_MAPTYPE) == HOOK_WIN16
1041 && data->id != WH_JOURNALPLAYBACK )
1042 ret = LOWORD( ret );
1043
Ulrich Weigand4b6b1c31999-05-17 14:55:30 +00001044 WIN_RestoreWndsLock(iWndsLocks);
1045
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001046 TRACE("Ret hook %04x = %08lx\n", hook, ret );
Alexandre Julliardade697e1995-11-26 13:59:11 +00001047
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001048 data->flags &= ~HOOK_INUSE;
Alexandre Julliardade697e1995-11-26 13:59:11 +00001049 queue->hCurHook = prevHook;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001050
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001051 QUEUE_Unlock( queue );
1052
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001053 if (UnMapFunc)
1054 UnMapFunc( data->id, code, wParamOrig, lParamOrig, wParam, lParam );
1055
Alexandre Julliardade697e1995-11-26 13:59:11 +00001056 if (!data->proc) HOOK_RemoveHook( hook );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001057
Alexandre Julliardade697e1995-11-26 13:59:11 +00001058 return ret;
1059}
1060
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001061/***********************************************************************
1062 * Exported Functions & APIs
1063 */
1064
1065/***********************************************************************
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001066 * HOOK_IsHooked
1067 *
1068 * Replacement for calling HOOK_GetHook from other modules.
1069 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001070BOOL HOOK_IsHooked( INT16 id )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001071{
Ulrich Weiganda8975181999-01-20 13:11:45 +00001072 /* Hmmm. Use GetThreadQueue(0) instead of GetFastQueue() here to
1073 avoid queue being created if someone wants to merely check ... */
1074
Alexandre Julliarda3960291999-02-26 11:11:13 +00001075 return HOOK_GetHook( id, GetThreadQueue16(0) ) != 0;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001076}
1077
1078
1079/***********************************************************************
1080 * HOOK_CallHooks16
Alexandre Julliardade697e1995-11-26 13:59:11 +00001081 *
1082 * Call a hook chain.
1083 */
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001084LRESULT HOOK_CallHooks16( INT16 id, INT16 code, WPARAM16 wParam,
1085 LPARAM lParam )
Alexandre Julliardade697e1995-11-26 13:59:11 +00001086{
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001087 HANDLE16 hook;
1088
Alexandre Julliarda3960291999-02-26 11:11:13 +00001089 if (!(hook = HOOK_GetHook( id, GetFastQueue16() ))) return 0;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001090 if (!(hook = HOOK_FindValidHook(hook))) return 0;
1091 return HOOK_CallHook( hook, HOOK_WIN16, code, wParam, lParam );
1092}
1093
1094/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001095 * HOOK_CallHooksA
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001096 *
1097 * Call a hook chain.
1098 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001099LRESULT HOOK_CallHooksA( INT id, INT code, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001100 LPARAM lParam )
1101{
1102 HANDLE16 hook;
1103
Alexandre Julliarda3960291999-02-26 11:11:13 +00001104 if (!(hook = HOOK_GetHook( id, GetFastQueue16() ))) return 0;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001105 if (!(hook = HOOK_FindValidHook(hook))) return 0;
Alexandre Julliard349a9531997-02-02 19:01:52 +00001106 return HOOK_CallHook( hook, HOOK_WIN32A, code, wParam, lParam );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001107}
1108
1109/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001110 * HOOK_CallHooksW
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001111 *
1112 * Call a hook chain.
1113 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001114LRESULT HOOK_CallHooksW( INT id, INT code, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001115 LPARAM lParam )
1116{
1117 HANDLE16 hook;
1118
Alexandre Julliarda3960291999-02-26 11:11:13 +00001119 if (!(hook = HOOK_GetHook( id, GetFastQueue16() ))) return 0;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001120 if (!(hook = HOOK_FindValidHook(hook))) return 0;
Alexandre Julliard349a9531997-02-02 19:01:52 +00001121 return HOOK_CallHook( hook, HOOK_WIN32W, code, wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001122 lParam );
Alexandre Julliardade697e1995-11-26 13:59:11 +00001123}
Alexandre Julliard58199531994-04-21 01:20:00 +00001124
1125
1126/***********************************************************************
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001127 * HOOK_ResetQueueHooks
1128 */
1129void HOOK_ResetQueueHooks( HQUEUE16 hQueue )
1130{
1131 MESSAGEQUEUE *queue;
1132
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001133 if ((queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue )) != NULL)
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001134 {
1135 HOOKDATA* data;
1136 HHOOK hook;
1137 int id;
1138 for( id = WH_MINHOOK; id <= WH_MAXHOOK; id++ )
1139 {
1140 hook = queue->hooks[id - WH_MINHOOK];
1141 while( hook )
1142 {
1143 if( (data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook)) )
1144 {
1145 data->ownerQueue = hQueue;
1146 hook = data->next;
1147 } else break;
1148 }
1149 }
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001150
1151 QUEUE_Unlock( queue );
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001152 }
1153}
1154
1155/***********************************************************************
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001156 * HOOK_FreeModuleHooks
1157 */
Alexandre Julliard3051b641996-07-05 17:14:13 +00001158void HOOK_FreeModuleHooks( HMODULE16 hModule )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001159{
1160 /* remove all system hooks registered by this module */
1161
1162 HOOKDATA* hptr;
1163 HHOOK hook, next;
1164 int id;
1165
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001166 for( id = WH_MINHOOK; id <= WH_MAXHOOK; id++ )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001167 {
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001168 hook = HOOK_systemHooks[id - WH_MINHOOK];
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001169 while( hook )
1170 if( (hptr = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook)) )
1171 {
1172 next = hptr->next;
1173 if( hptr->ownerModule == hModule )
1174 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001175 hptr->flags &= HOOK_MAPTYPE;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001176 HOOK_RemoveHook(hook);
1177 }
1178 hook = next;
1179 }
1180 else hook = 0;
1181 }
1182}
1183
1184/***********************************************************************
1185 * HOOK_FreeQueueHooks
1186 */
Alexandre Julliard3051b641996-07-05 17:14:13 +00001187void HOOK_FreeQueueHooks( HQUEUE16 hQueue )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001188{
1189 /* remove all hooks registered by this queue */
1190
1191 HOOKDATA* hptr = NULL;
1192 HHOOK hook, next;
1193 int id;
1194
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001195 for( id = WH_MINHOOK; id <= WH_MAXHOOK; id++ )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001196 {
1197 hook = HOOK_GetHook( id, hQueue );
1198 while( hook )
1199 {
1200 next = HOOK_GetNextHook(hook);
1201
1202 hptr = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook);
1203 if( hptr && hptr->ownerQueue == hQueue )
1204 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001205 hptr->flags &= HOOK_MAPTYPE;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001206 HOOK_RemoveHook(hook);
1207 }
1208 hook = next;
1209 }
1210 }
1211}
1212
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001213
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001214/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001215 * SetWindowsHook16 (USER.121)
Alexandre Julliard58199531994-04-21 01:20:00 +00001216 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001217FARPROC16 WINAPI SetWindowsHook16( INT16 id, HOOKPROC16 proc )
Alexandre Julliard58199531994-04-21 01:20:00 +00001218{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001219 HINSTANCE16 hInst = FarGetOwner16( HIWORD(proc) );
Alexandre Julliardade697e1995-11-26 13:59:11 +00001220
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001221 /* WH_MSGFILTER is the only task-specific hook for SetWindowsHook() */
1222 HTASK16 hTask = (id == WH_MSGFILTER) ? GetCurrentTask() : 0;
1223
Ulrich Weiganda8975181999-01-20 13:11:45 +00001224 return (FARPROC16)SetWindowsHookEx16( id, proc, hInst, hTask );
Alexandre Julliard58199531994-04-21 01:20:00 +00001225}
1226
Alexandre Julliard58199531994-04-21 01:20:00 +00001227/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001228 * SetWindowsHookA (USER32.@)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001229 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001230HHOOK WINAPI SetWindowsHookA( INT id, HOOKPROC proc )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001231{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001232 return SetWindowsHookExA( id, proc, 0, GetCurrentThreadId() );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001233}
1234
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001235/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001236 * SetWindowsHookW (USER32.@)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001237 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001238HHOOK WINAPI SetWindowsHookW( INT id, HOOKPROC proc )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001239{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001240 return SetWindowsHookExW( id, proc, 0, GetCurrentThreadId() );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001241}
1242
1243
1244/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001245 * SetWindowsHookEx16 (USER.291) (USER32.@)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001246 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001247HHOOK WINAPI SetWindowsHookEx16( INT16 id, HOOKPROC16 proc, HINSTANCE16 hInst,
1248 HTASK16 hTask )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001249{
Ulrich Weiganda8975181999-01-20 13:11:45 +00001250 if (id == WH_DEBUG)
1251 {
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001252 FIXME("WH_DEBUG is broken in 16-bit Windows.\n");
Ulrich Weiganda8975181999-01-20 13:11:45 +00001253 return 0;
1254 }
1255 return HOOK_SetHook( id, proc, HOOK_WIN16, GetExePtr(hInst), (DWORD)hTask );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001256}
1257
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001258/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001259 * SetWindowsHookExA (USER32.@)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001260 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001261HHOOK WINAPI SetWindowsHookExA( INT id, HOOKPROC proc, HINSTANCE hInst,
Ulrich Weiganda8975181999-01-20 13:11:45 +00001262 DWORD dwThreadId )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001263{
Ulrich Weiganda8975181999-01-20 13:11:45 +00001264 return HOOK_SetHook( id, proc, HOOK_WIN32A, MapHModuleLS(hInst), dwThreadId );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001265}
1266
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001267/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001268 * SetWindowsHookExW (USER32.@)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001269 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001270HHOOK WINAPI SetWindowsHookExW( INT id, HOOKPROC proc, HINSTANCE hInst,
Ulrich Weiganda8975181999-01-20 13:11:45 +00001271 DWORD dwThreadId )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001272{
Ulrich Weiganda8975181999-01-20 13:11:45 +00001273 return HOOK_SetHook( id, proc, HOOK_WIN32W, MapHModuleLS(hInst), dwThreadId );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001274}
1275
1276
1277/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001278 * UnhookWindowsHook (USER.234)
Alexandre Julliard58199531994-04-21 01:20:00 +00001279 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001280BOOL16 WINAPI UnhookWindowsHook16( INT16 id, HOOKPROC16 proc )
Alexandre Julliard58199531994-04-21 01:20:00 +00001281{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001282 return UnhookWindowsHook( id, (HOOKPROC)proc );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001283}
1284
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001285/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001286 * UnhookWindowsHook (USER32.@)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001287 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001288BOOL WINAPI UnhookWindowsHook( INT id, HOOKPROC proc )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001289{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001290 HANDLE16 hook = HOOK_GetHook( id, GetFastQueue16() );
Alexandre Julliard594997c1995-04-30 10:05:20 +00001291
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001292 TRACE("%d %08lx\n", id, (DWORD)proc );
Alexandre Julliardade697e1995-11-26 13:59:11 +00001293
1294 while (hook)
1295 {
1296 HOOKDATA *data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook);
1297 if (data->proc == proc) break;
1298 hook = HOOK_GetNextHook( hook );
Alexandre Julliard594997c1995-04-30 10:05:20 +00001299 }
Alexandre Julliardade697e1995-11-26 13:59:11 +00001300 if (!hook) return FALSE;
1301 return HOOK_RemoveHook( hook );
Alexandre Julliard58199531994-04-21 01:20:00 +00001302}
1303
1304
1305/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001306 * UnhookWindowsHookEx (USER.292)
Alexandre Julliard58199531994-04-21 01:20:00 +00001307 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001308BOOL16 WINAPI UnhookWindowsHookEx16( HHOOK hhook )
Alexandre Julliard58199531994-04-21 01:20:00 +00001309{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001310 return UnhookWindowsHookEx( hhook );
Alexandre Julliard58199531994-04-21 01:20:00 +00001311}
1312
Alexandre Julliard58199531994-04-21 01:20:00 +00001313/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001314 * UnhookWindowsHookEx (USER32.@)
Alexandre Julliard58199531994-04-21 01:20:00 +00001315 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001316BOOL WINAPI UnhookWindowsHookEx( HHOOK hhook )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001317{
Ulrich Weiganda8975181999-01-20 13:11:45 +00001318 if (HIWORD(hhook) != HOOK_MAGIC) return FALSE; /* Not a new format hook */
1319 return HOOK_RemoveHook( LOWORD(hhook) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001320}
1321
1322
1323/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001324 * CallNextHookEx16 (USER.293) (USER32.@)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001325 *
1326 * I wouldn't have separated this into 16 and 32 bit versions, but I
1327 * need a way to figure out if I need to do a mapping or not.
1328 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001329LRESULT WINAPI CallNextHookEx16( HHOOK hhook, INT16 code, WPARAM16 wParam,
1330 LPARAM lParam )
Alexandre Julliard58199531994-04-21 01:20:00 +00001331{
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001332 HANDLE16 next;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001333
Alexandre Julliardade697e1995-11-26 13:59:11 +00001334 if (HIWORD(hhook) != HOOK_MAGIC) return 0; /* Not a new format hook */
1335 if (!(next = HOOK_GetNextHook( LOWORD(hhook) ))) return 0;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001336
1337 return HOOK_CallHook( next, HOOK_WIN16, code, wParam, lParam );
1338}
1339
1340
1341/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001342 * CallNextHookEx (USER32.@)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001343 *
1344 * There aren't ANSI and UNICODE versions of this.
1345 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001346LRESULT WINAPI CallNextHookEx( HHOOK hhook, INT code, WPARAM wParam,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001347 LPARAM lParam )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001348{
1349 HANDLE16 next;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001350 INT fromtype; /* figure out Ansi/Unicode */
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001351 HOOKDATA *oldhook;
1352
1353 if (HIWORD(hhook) != HOOK_MAGIC) return 0; /* Not a new format hook */
1354 if (!(next = HOOK_GetNextHook( LOWORD(hhook) ))) return 0;
1355
1356 oldhook = (HOOKDATA *)USER_HEAP_LIN_ADDR( LOWORD(hhook) );
1357 fromtype = oldhook->flags & HOOK_MAPTYPE;
1358
Alexandre Julliard349a9531997-02-02 19:01:52 +00001359 if (fromtype == HOOK_WIN16)
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001360 ERR("called from 16bit hook!\n");
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001361
1362 return HOOK_CallHook( next, fromtype, code, wParam, lParam );
1363}
1364
1365
1366/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001367 * DefHookProc (USER.235)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001368 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001369LRESULT WINAPI DefHookProc16( INT16 code, WPARAM16 wParam, LPARAM lParam,
1370 HHOOK *hhook )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001371{
1372 /* Note: the *hhook parameter is never used, since we rely on the
1373 * current hook value from the task queue to find the next hook. */
1374 MESSAGEQUEUE *queue;
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001375 LRESULT ret;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001376
Alexandre Julliarda3960291999-02-26 11:11:13 +00001377 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0;
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001378 ret = CallNextHookEx16( queue->hCurHook, code, wParam, lParam );
1379 QUEUE_Unlock( queue );
1380 return ret;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001381}
1382
1383
1384/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001385 * CallMsgFilter (USER.123)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001386 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001387BOOL16 WINAPI CallMsgFilter16( SEGPTR msg, INT16 code )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001388{
1389 if (GetSysModalWindow16()) return FALSE;
1390 if (HOOK_CallHooks16( WH_SYSMSGFILTER, code, 0, (LPARAM)msg )) return TRUE;
1391 return HOOK_CallHooks16( WH_MSGFILTER, code, 0, (LPARAM)msg );
1392}
1393
1394
1395/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001396 * CallMsgFilter32 (USER.823)
Andreas Mohr94e44851999-01-23 14:15:17 +00001397 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001398BOOL16 WINAPI CallMsgFilter32_16( SEGPTR msg16_32, INT16 code, BOOL16 wHaveParamHigh )
Andreas Mohr94e44851999-01-23 14:15:17 +00001399{
Alexandre Julliard982a2232000-12-13 20:20:09 +00001400 MSG32_16 *lpmsg16_32 = MapSL(msg16_32);
Andreas Mohr94e44851999-01-23 14:15:17 +00001401
1402 if (wHaveParamHigh == FALSE)
1403 {
1404 lpmsg16_32->wParamHigh = 0;
1405 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1406 return CallMsgFilter16(msg16_32, code);
1407 }
1408 else
1409 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001410 MSG msg32;
Andreas Mohr94e44851999-01-23 14:15:17 +00001411 BOOL16 ret;
1412
1413 msg32.hwnd = lpmsg16_32->msg.hwnd;
1414 msg32.message = lpmsg16_32->msg.message;
1415 msg32.wParam =
1416 MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
1417 msg32.lParam = lpmsg16_32->msg.lParam;
1418 msg32.time = lpmsg16_32->msg.time;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001419 msg32.pt.x = (INT)lpmsg16_32->msg.pt.x;
1420 msg32.pt.y = (INT)lpmsg16_32->msg.pt.y;
Andreas Mohr94e44851999-01-23 14:15:17 +00001421
Alexandre Julliarda3960291999-02-26 11:11:13 +00001422 ret = (BOOL16)CallMsgFilterA(&msg32, (INT)code);
Andreas Mohr94e44851999-01-23 14:15:17 +00001423
1424 lpmsg16_32->msg.hwnd = msg32.hwnd;
1425 lpmsg16_32->msg.message = msg32.message;
1426 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1427 lpmsg16_32->msg.lParam = msg32.lParam;
1428 lpmsg16_32->msg.time = msg32.time;
1429 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1430 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1431 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1432
1433 return ret;
1434 }
1435}
1436
1437
1438/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001439 * CallMsgFilterA (USER32.@)
Patrik Stridvall2b3aa612000-12-01 23:58:28 +00001440 *
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001441 * FIXME: There are ANSI and UNICODE versions of this, plus an unspecified
1442 * version, plus USER (the 16bit one) has a CallMsgFilter32 function.
1443 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001444BOOL WINAPI CallMsgFilterA( LPMSG msg, INT code )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001445{
1446 if (GetSysModalWindow16()) return FALSE; /* ??? */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001447 if (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0, (LPARAM)msg ))
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001448 return TRUE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001449 return HOOK_CallHooksA( WH_MSGFILTER, code, 0, (LPARAM)msg );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001450}
1451
1452
1453/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001454 * CallMsgFilterW (USER32.@)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001455 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001456BOOL WINAPI CallMsgFilterW( LPMSG msg, INT code )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001457{
1458 if (GetSysModalWindow16()) return FALSE; /* ??? */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001459 if (HOOK_CallHooksW( WH_SYSMSGFILTER, code, 0, (LPARAM)msg ))
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001460 return TRUE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001461 return HOOK_CallHooksW( WH_MSGFILTER, code, 0, (LPARAM)msg );
Alexandre Julliard58199531994-04-21 01:20:00 +00001462}
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001463