blob: 5c591d3d16d36391138d0891496083215637ea3a [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"
18#include "wingdi.h"
Marcus Meissner61afa331999-02-22 10:16:00 +000019#include "winuser.h"
20#include "wine/winuser16.h"
21#include "wine/winbase16.h"
Ulrich Weigandf4edf231999-09-20 18:45:00 +000022#include "callback.h"
Alexandre Julliard58199531994-04-21 01:20:00 +000023#include "hook.h"
Ulrich Weigand4b6b1c31999-05-17 14:55:30 +000024#include "win.h"
Alexandre Julliardb817f4f1996-03-14 18:08:34 +000025#include "queue.h"
Ulrich Weigand1babe5b1998-12-24 15:16:08 +000026#include "task.h"
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000027#include "user.h"
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000028#include "heap.h"
29#include "struct32.h"
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000030#include "winproc.h"
Alexandre Julliard359f497e1999-07-04 16:02:24 +000031#include "debugtools.h"
Alexandre Julliard58199531994-04-21 01:20:00 +000032
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000033DEFAULT_DEBUG_CHANNEL(hook)
34
Patrik Stridvallc7a8dde1999-04-25 12:36:53 +000035#include "pshpack1.h"
Alexandre Julliardbf9130a1996-10-13 17:45:47 +000036
37 /* Hook data (pointed to by a HHOOK) */
38typedef struct
39{
40 HANDLE16 next; /* 00 Next hook in chain */
Ulrich Weigandf4edf231999-09-20 18:45:00 +000041 HOOKPROC proc; /* 02 Hook procedure (original) */
Alexandre Julliardbf9130a1996-10-13 17:45:47 +000042 INT16 id; /* 06 Hook id (WH_xxx) */
43 HQUEUE16 ownerQueue; /* 08 Owner queue (0 for system hook) */
44 HMODULE16 ownerModule; /* 0a Owner module */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000045 WORD flags; /* 0c flags */
Ulrich Weigandf4edf231999-09-20 18:45:00 +000046 HOOKPROC thunk; /* 0e Hook procedure (CallTo16 thunk) */
Alexandre Julliardbf9130a1996-10-13 17:45:47 +000047} HOOKDATA;
48
Patrik Stridvallc7a8dde1999-04-25 12:36:53 +000049#include "poppack.h"
Alexandre Julliardbf9130a1996-10-13 17:45:47 +000050
51#define HOOK_MAGIC ((int)'H' | (int)'K' << 8) /* 'HK' */
52
Alexandre Julliardade697e1995-11-26 13:59:11 +000053 /* This should probably reside in USER heap */
Alexandre Julliard3051b641996-07-05 17:14:13 +000054static HANDLE16 HOOK_systemHooks[WH_NB_HOOKS] = { 0, };
Alexandre Julliard58199531994-04-21 01:20:00 +000055
Alexandre Julliarda3960291999-02-26 11:11:13 +000056typedef VOID (*HOOK_MapFunc)(INT, INT, WPARAM *, LPARAM *);
57typedef VOID (*HOOK_UnMapFunc)(INT, INT, WPARAM, LPARAM, WPARAM,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000058 LPARAM);
59
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000060/***********************************************************************
61 * HOOK_Map16To32Common
62 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000063static void HOOK_Map16To32Common(INT id, INT code, WPARAM *pwParam,
64 LPARAM *plParam, BOOL bA )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000065{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000066
67 switch( id )
68 {
69 case WH_MSGFILTER:
70 case WH_SYSMSGFILTER:
71 case WH_GETMESSAGE:
72 case WH_JOURNALRECORD:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000073 {
74 LPMSG16 lpmsg16 = PTR_SEG_TO_LIN(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +000075 LPMSG lpmsg32 = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpmsg32) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000076
77 STRUCT32_MSG16to32( lpmsg16, lpmsg32 );
78 *plParam = (LPARAM)lpmsg32;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000079 break;
80 }
81
82 case WH_JOURNALPLAYBACK:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000083 {
84 LPEVENTMSG16 lpem16 = PTR_SEG_TO_LIN(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +000085 LPEVENTMSG lpem32 = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpem32) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000086
87 lpem32->message = lpem16->message;
88 lpem32->paramL = lpem16->paramL;
89 lpem32->paramH = lpem16->paramH;
90 lpem32->time = lpem16->time;
91 lpem32->hwnd = 0; /* FIXME */
92
93 *plParam = (LPARAM)lpem32;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000094 break;
95 }
96
97 case WH_CALLWNDPROC:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +000098 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000099 LPCWPSTRUCT16 lpcwp16 = PTR_SEG_TO_LIN(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000100 LPCWPSTRUCT lpcwp32 = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpcwp32) );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000101
102 lpcwp32->hwnd = lpcwp16->hwnd;
103 lpcwp32->lParam = lpcwp16->lParam;
104
Alexandre Julliard77b99181997-09-14 17:17:23 +0000105 if (bA) WINPROC_MapMsg16To32A( lpcwp16->message, lpcwp16->wParam,
106 &lpcwp32->message, &lpcwp32->wParam,
107 &lpcwp32->lParam );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000108 else WINPROC_MapMsg16To32W( lpcwp16->hwnd,lpcwp16->message, lpcwp16->wParam,
Alexandre Julliard77b99181997-09-14 17:17:23 +0000109 &lpcwp32->message, &lpcwp32->wParam,
110 &lpcwp32->lParam );
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000111 *plParam = (LPARAM)lpcwp32;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000112 break;
113 }
114
115 case WH_CBT:
116 switch (code)
117 {
118 case HCBT_CREATEWND:
119 {
120 LPCBT_CREATEWND16 lpcbtcw16 = PTR_SEG_TO_LIN(*plParam);
121 LPCREATESTRUCT16 lpcs16 = PTR_SEG_TO_LIN(lpcbtcw16->lpcs);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000122 LPCBT_CREATEWNDA lpcbtcw32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000123 sizeof(*lpcbtcw32) );
Alexandre Julliard90476d62000-02-16 22:47:24 +0000124 lpcbtcw32->lpcs = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000125 sizeof(*lpcbtcw32->lpcs) );
126
127 STRUCT32_CREATESTRUCT16to32A( lpcs16,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000128 (LPCREATESTRUCTA)lpcbtcw32->lpcs );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000129
130 if (HIWORD(lpcs16->lpszName))
131 lpcbtcw32->lpcs->lpszName =
132 (bA) ? PTR_SEG_TO_LIN(lpcs16->lpszName)
Alexandre Julliard90476d62000-02-16 22:47:24 +0000133 : HEAP_strdupAtoW( GetProcessHeap(), 0,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000134 PTR_SEG_TO_LIN(lpcs16->lpszName) );
135 else
136 lpcbtcw32->lpcs->lpszName = (LPCSTR)lpcs16->lpszName;
137
138 if (HIWORD(lpcs16->lpszClass))
139 lpcbtcw32->lpcs->lpszClass =
140 (bA) ? PTR_SEG_TO_LIN(lpcs16->lpszClass)
Alexandre Julliard90476d62000-02-16 22:47:24 +0000141 : HEAP_strdupAtoW( GetProcessHeap(), 0,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000142 PTR_SEG_TO_LIN(lpcs16->lpszClass) );
143 else
144 lpcbtcw32->lpcs->lpszClass = (LPCSTR)lpcs16->lpszClass;
145
146 lpcbtcw32->hwndInsertAfter = lpcbtcw16->hwndInsertAfter;
147
148 *plParam = (LPARAM)lpcbtcw32;
149 break;
150 }
151 case HCBT_ACTIVATE:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000152 {
153 LPCBTACTIVATESTRUCT16 lpcas16 = PTR_SEG_TO_LIN(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000154 LPCBTACTIVATESTRUCT lpcas32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000155 sizeof(*lpcas32) );
156 lpcas32->fMouse = lpcas16->fMouse;
157 lpcas32->hWndActive = lpcas16->hWndActive;
158 *plParam = (LPARAM)lpcas32;
159 break;
160 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000161 case HCBT_CLICKSKIPPED:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000162 {
163 LPMOUSEHOOKSTRUCT16 lpms16 = PTR_SEG_TO_LIN(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000164 LPMOUSEHOOKSTRUCT lpms32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000165 sizeof(*lpms32) );
166
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000167 CONV_POINT16TO32( &lpms16->pt, &lpms32->pt );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000168
169 /* wHitTestCode may be negative, so convince compiler to do
170 correct sign extension. Yay. :| */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000171 lpms32->wHitTestCode = (INT)((INT16)lpms16->wHitTestCode);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000172
173 lpms32->dwExtraInfo = lpms16->dwExtraInfo;
174 lpms32->hwnd = lpms16->hwnd;
175 *plParam = (LPARAM)lpms32;
176 break;
177 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000178 case HCBT_MOVESIZE:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000179 {
180 LPRECT16 lprect16 = PTR_SEG_TO_LIN(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000181 LPRECT lprect32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000182 sizeof(*lprect32) );
183
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000184 CONV_RECT16TO32( lprect16, lprect32 );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000185 *plParam = (LPARAM)lprect32;
186 break;
187 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000188 }
Alexandre Julliard21979011997-03-05 08:22:35 +0000189 break;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000190
191 case WH_MOUSE:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000192 {
193 LPMOUSEHOOKSTRUCT16 lpms16 = PTR_SEG_TO_LIN(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000194 LPMOUSEHOOKSTRUCT lpms32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000195 sizeof(*lpms32) );
196
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000197 CONV_POINT16TO32( &lpms16->pt, &lpms32->pt );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000198
199 /* wHitTestCode may be negative, so convince compiler to do
200 correct sign extension. Yay. :| */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000201 lpms32->wHitTestCode = (INT)((INT16)lpms16->wHitTestCode);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000202 lpms32->dwExtraInfo = lpms16->dwExtraInfo;
203 lpms32->hwnd = lpms16->hwnd;
204 *plParam = (LPARAM)lpms32;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000205 break;
206 }
207
208 case WH_DEBUG:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000209 {
210 LPDEBUGHOOKINFO16 lpdh16 = PTR_SEG_TO_LIN(*plParam);
Alexandre Julliard90476d62000-02-16 22:47:24 +0000211 LPDEBUGHOOKINFO lpdh32 = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000212 sizeof(*lpdh32) );
213
214 lpdh32->idThread = 0; /* FIXME */
215 lpdh32->idThreadInstaller = 0; /* FIXME */
216 lpdh32->lParam = lpdh16->lParam; /* FIXME Check for sign ext */
217 lpdh32->wParam = lpdh16->wParam;
218 lpdh32->code = lpdh16->code;
219
220 /* do sign extension if it was WH_MSGFILTER */
221 if (*pwParam == 0xffff) *pwParam = WH_MSGFILTER;
222
223 *plParam = (LPARAM)lpdh32;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000224 break;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000225 }
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000226
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000227 case WH_SHELL:
228 case WH_KEYBOARD:
229 break;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000230
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000231 case WH_HARDWARE:
232 case WH_FOREGROUNDIDLE:
233 case WH_CALLWNDPROCRET:
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000234 FIXME("\t[%i] 16to32 translation unimplemented\n", id);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000235 }
236}
237
238
239/***********************************************************************
240 * HOOK_Map16To32A
241 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000242static void HOOK_Map16To32A(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000243 LPARAM *plParam)
244{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000245 HOOK_Map16To32Common( id, code, pwParam, plParam, TRUE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000246}
247
248
249/***********************************************************************
250 * HOOK_Map16To32W
251 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000252static void HOOK_Map16To32W(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000253 LPARAM *plParam)
254{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000255 HOOK_Map16To32Common( id, code, pwParam, plParam, FALSE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000256}
257
258
259/***********************************************************************
260 * HOOK_UnMap16To32Common
261 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000262static void HOOK_UnMap16To32Common(INT id, INT code, WPARAM wParamOrig,
263 LPARAM lParamOrig, WPARAM wParam,
264 LPARAM lParam, BOOL bA)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000265{
266 switch (id)
267 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000268 case WH_MSGFILTER:
269 case WH_SYSMSGFILTER:
270 case WH_JOURNALRECORD:
271 case WH_JOURNALPLAYBACK:
272
Alexandre Julliard90476d62000-02-16 22:47:24 +0000273 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000274 break;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000275
276 case WH_CALLWNDPROC:
277 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000278 LPCWPSTRUCT lpcwp32 = (LPCWPSTRUCT)lParam;
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000279 if (bA) WINPROC_UnmapMsg16To32A( lpcwp32->hwnd,lpcwp32->message, lpcwp32->wParam,
Alexandre Julliard491502b1997-11-01 19:08:16 +0000280 lpcwp32->lParam, 0 );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000281 else WINPROC_UnmapMsg16To32W( lpcwp32->hwnd,lpcwp32->message, lpcwp32->wParam,
Alexandre Julliard491502b1997-11-01 19:08:16 +0000282 lpcwp32->lParam, 0 );
Alexandre Julliard90476d62000-02-16 22:47:24 +0000283 HeapFree( GetProcessHeap(), 0, lpcwp32 );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000284 break;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000285 }
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000286
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000287 case WH_GETMESSAGE:
288 {
289 LPMSG16 lpmsg16 = PTR_SEG_TO_LIN(lParamOrig);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000290 STRUCT32_MSG32to16( (LPMSG)lParam, lpmsg16 );
Alexandre Julliard90476d62000-02-16 22:47:24 +0000291 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000292 break;
293 }
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000294
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000295 case WH_MOUSE:
296 case WH_DEBUG:
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000297
Alexandre Julliard90476d62000-02-16 22:47:24 +0000298 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000299 break;
300
301 case WH_CBT:
302 switch (code)
303 {
304 case HCBT_CREATEWND:
305 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000306 LPCBT_CREATEWNDA lpcbtcw32 = (LPCBT_CREATEWNDA)lParam;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000307 LPCBT_CREATEWND16 lpcbtcw16 = PTR_SEG_TO_LIN(lParamOrig);
308
309 if( !bA )
310 {
311 if (HIWORD(lpcbtcw32->lpcs->lpszName))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000312 HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcw32->lpcs->lpszName );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000313 if (HIWORD(lpcbtcw32->lpcs->lpszClass))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000314 HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcw32->lpcs->lpszClass );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000315 }
316
317 lpcbtcw16->hwndInsertAfter = lpcbtcw32->hwndInsertAfter;
318
Alexandre Julliard90476d62000-02-16 22:47:24 +0000319 HeapFree( GetProcessHeap(), 0, lpcbtcw32->lpcs );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000320 } /* fall through */
321
322 case HCBT_ACTIVATE:
323 case HCBT_CLICKSKIPPED:
324 case HCBT_MOVESIZE:
325
Alexandre Julliard90476d62000-02-16 22:47:24 +0000326 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000327 break;
328 }
329 break;
330
331 case WH_SHELL:
332 case WH_KEYBOARD:
333 break;
334
335 case WH_HARDWARE:
336 case WH_FOREGROUNDIDLE:
337 case WH_CALLWNDPROCRET:
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000338 FIXME("\t[%i] skipping unmap\n", id);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000339 break;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000340 }
341}
342
343
344/***********************************************************************
345 * HOOK_UnMap16To32A
346 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000347static void HOOK_UnMap16To32A(INT id, INT code, WPARAM wParamOrig,
348 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000349 LPARAM lParam)
350{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000351 HOOK_UnMap16To32Common( id, code, wParamOrig, lParamOrig, wParam,
352 lParam, TRUE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000353}
354
355
356/***********************************************************************
357 * HOOK_UnMap16To32W
358 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000359static void HOOK_UnMap16To32W(INT id, INT code, WPARAM wParamOrig,
360 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000361 LPARAM lParam)
362{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000363 HOOK_UnMap16To32Common( id, code, wParamOrig, lParamOrig, wParam,
364 lParam, FALSE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000365}
366
367
368/***********************************************************************
369 * HOOK_Map32To16Common
370 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000371static void HOOK_Map32To16Common(INT id, INT code, WPARAM *pwParam,
372 LPARAM *plParam, BOOL bA)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000373{
374 switch (id)
375 {
376 case WH_MSGFILTER:
377 case WH_SYSMSGFILTER:
378 case WH_GETMESSAGE:
379 case WH_JOURNALRECORD:
380 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000381 LPMSG lpmsg32 = (LPMSG)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000382 LPMSG16 lpmsg16 = SEGPTR_NEW( MSG16 );
383
384 STRUCT32_MSG32to16( lpmsg32, lpmsg16 );
385
386 *plParam = (LPARAM)SEGPTR_GET( lpmsg16 );
387 break;
388 }
389
390 case WH_JOURNALPLAYBACK:
391 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000392 LPEVENTMSG lpem32 = (LPEVENTMSG)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000393 LPEVENTMSG16 lpem16 = SEGPTR_NEW( EVENTMSG16 );
394
395 lpem16->message = lpem32->message;
396 lpem16->paramL = lpem32->paramL;
397 lpem16->paramH = lpem32->paramH;
398 lpem16->time = lpem32->time;
399
400 *plParam = (LPARAM)SEGPTR_GET( lpem16 );
401 break;
402 }
403
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000404 case WH_CALLWNDPROC:
405 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000406 LPCWPSTRUCT lpcwp32 = (LPCWPSTRUCT)*plParam;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000407 LPCWPSTRUCT16 lpcwp16 = SEGPTR_NEW( CWPSTRUCT16 );
408
409 lpcwp16->hwnd = lpcwp32->hwnd;
410 lpcwp16->lParam = lpcwp32->lParam;
411
Alexandre Julliard491502b1997-11-01 19:08:16 +0000412 if (bA) WINPROC_MapMsg32ATo16( lpcwp32->hwnd, lpcwp32->message,
413 lpcwp32->wParam, &lpcwp16->message,
414 &lpcwp16->wParam, &lpcwp16->lParam );
415 else WINPROC_MapMsg32WTo16( lpcwp32->hwnd, lpcwp32->message,
416 lpcwp32->wParam, &lpcwp16->message,
417 &lpcwp16->wParam, &lpcwp16->lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000418 *plParam = (LPARAM)SEGPTR_GET( lpcwp16 );
419 break;
420 }
421
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000422 case WH_CBT:
423 switch (code)
424 {
425 case HCBT_ACTIVATE:
426 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000427 LPCBTACTIVATESTRUCT lpcas32 = (LPCBTACTIVATESTRUCT)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000428 LPCBTACTIVATESTRUCT16 lpcas16 =SEGPTR_NEW( CBTACTIVATESTRUCT16 );
429
430 lpcas16->fMouse = lpcas32->fMouse;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000431 lpcas16->hWndActive = lpcas32->hWndActive;
432
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000433 *plParam = (LPARAM)SEGPTR_GET( lpcas16 );
434 break;
435 }
436
437 case HCBT_CLICKSKIPPED:
438 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000439 LPMOUSEHOOKSTRUCT lpms32 = (LPMOUSEHOOKSTRUCT)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000440 LPMOUSEHOOKSTRUCT16 lpms16 = SEGPTR_NEW( MOUSEHOOKSTRUCT16 );
441
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000442 CONV_POINT32TO16( &lpms32->pt, &lpms16->pt );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000443
444 lpms16->hwnd = lpms32->hwnd;
445 lpms16->wHitTestCode = lpms32->wHitTestCode;
446 lpms16->dwExtraInfo = lpms32->dwExtraInfo;
447
448 *plParam = (LPARAM)SEGPTR_GET( lpms16 );
449 break;
450 }
451
452 case HCBT_MOVESIZE:
453 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000454 LPRECT lprect32 = (LPRECT)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000455 LPRECT16 lprect16 = SEGPTR_NEW( RECT16 );
456
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000457 CONV_RECT32TO16( lprect32, lprect16 );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000458
459 *plParam = (LPARAM)SEGPTR_GET( lprect16 );
460 break;
461 }
462 }
463 break;
464
465 case WH_MOUSE:
466 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000467 LPMOUSEHOOKSTRUCT lpms32 = (LPMOUSEHOOKSTRUCT)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000468 LPMOUSEHOOKSTRUCT16 lpms16 = SEGPTR_NEW( MOUSEHOOKSTRUCT16 );
469
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000470 CONV_POINT32TO16( &lpms32->pt, &lpms16->pt );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000471
472 lpms16->hwnd = lpms32->hwnd;
473 lpms16->wHitTestCode = lpms32->wHitTestCode;
474 lpms16->dwExtraInfo = lpms32->dwExtraInfo;
475
476 *plParam = (LPARAM)SEGPTR_GET( lpms16 );
477 break;
478 }
479
480 case WH_DEBUG:
481 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000482 LPDEBUGHOOKINFO lpdh32 = (LPDEBUGHOOKINFO)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000483 LPDEBUGHOOKINFO16 lpdh16 = SEGPTR_NEW( DEBUGHOOKINFO16 );
484
485 lpdh16->hModuleHook = 0; /* FIXME */
486 lpdh16->reserved = 0;
487 lpdh16->lParam = lpdh32->lParam;
488 lpdh16->wParam = lpdh32->wParam;
489 lpdh16->code = lpdh32->code;
490
491 *plParam = (LPARAM)SEGPTR_GET( lpdh16 );
492 break;
493 }
494
495 case WH_SHELL:
496 case WH_KEYBOARD:
497 break;
498
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000499 case WH_HARDWARE:
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000500 case WH_FOREGROUNDIDLE:
501 case WH_CALLWNDPROCRET:
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000502 FIXME("\t[%i] 32to16 translation unimplemented\n", id);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000503 }
504}
505
506
507/***********************************************************************
508 * HOOK_Map32ATo16
509 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000510static void HOOK_Map32ATo16(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000511 LPARAM *plParam)
512{
513 if (id == WH_CBT && code == HCBT_CREATEWND)
514 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000515 LPCBT_CREATEWNDA lpcbtcw32 = (LPCBT_CREATEWNDA)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000516 LPCBT_CREATEWND16 lpcbtcw16 = SEGPTR_NEW( CBT_CREATEWND16 );
517 LPCREATESTRUCT16 lpcs16 = SEGPTR_NEW( CREATESTRUCT16 );
518
519 lpcbtcw16->lpcs = (LPCREATESTRUCT16)SEGPTR_GET( lpcs16 );
520 STRUCT32_CREATESTRUCT32Ato16( lpcbtcw32->lpcs, lpcs16 );
521
522 if (HIWORD(lpcbtcw32->lpcs->lpszName))
523 lpcs16->lpszName =
524 SEGPTR_GET( SEGPTR_STRDUP( lpcbtcw32->lpcs->lpszName ) );
525 else
526 lpcs16->lpszName = (SEGPTR)lpcbtcw32->lpcs->lpszName;
527
528 if (HIWORD(lpcbtcw32->lpcs->lpszClass))
529 lpcs16->lpszClass =
530 SEGPTR_GET( SEGPTR_STRDUP( lpcbtcw32->lpcs->lpszClass ) );
531 else
532 lpcs16->lpszClass = (SEGPTR)lpcbtcw32->lpcs->lpszClass;
533
534 lpcbtcw16->hwndInsertAfter = lpcbtcw32->hwndInsertAfter;
535
536 *plParam = (LPARAM)SEGPTR_GET( lpcbtcw16 );
537 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000538 else HOOK_Map32To16Common(id, code, pwParam, plParam, TRUE);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000539}
540
541
542/***********************************************************************
543 * HOOK_Map32WTo16
544 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000545static void HOOK_Map32WTo16(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000546 LPARAM *plParam)
547{
548 if (id == WH_CBT && code == HCBT_CREATEWND)
549 {
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000550 LPSTR name, cls;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000551 LPCBT_CREATEWNDW lpcbtcw32 = (LPCBT_CREATEWNDW)*plParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000552 LPCBT_CREATEWND16 lpcbtcw16 = SEGPTR_NEW( CBT_CREATEWND16 );
553 LPCREATESTRUCT16 lpcs16 = SEGPTR_NEW( CREATESTRUCT16 );
554
555 lpcbtcw16->lpcs = (LPCREATESTRUCT16)SEGPTR_GET( lpcs16 );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000556 STRUCT32_CREATESTRUCT32Ato16( (LPCREATESTRUCTA)lpcbtcw32->lpcs,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000557 lpcs16 );
558
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000559 name = SEGPTR_STRDUP_WtoA( lpcbtcw32->lpcs->lpszName );
560 cls = SEGPTR_STRDUP_WtoA( lpcbtcw32->lpcs->lpszClass );
561 lpcs16->lpszName = SEGPTR_GET( name );
562 lpcs16->lpszClass = SEGPTR_GET( cls );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000563 lpcbtcw16->hwndInsertAfter = lpcbtcw32->hwndInsertAfter;
564
565 *plParam = (LPARAM)SEGPTR_GET( lpcbtcw16 );
566 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000567 else HOOK_Map32To16Common(id, code, pwParam, plParam, FALSE);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000568}
569
570
571/***********************************************************************
572 * HOOK_UnMap32To16Common
573 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000574static void HOOK_UnMap32To16Common(INT id, INT code, WPARAM wParamOrig,
575 LPARAM lParamOrig, WPARAM wParam,
576 LPARAM lParam, BOOL bA)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000577{
578 switch (id)
579 {
580 case WH_MSGFILTER:
581 case WH_SYSMSGFILTER:
582 case WH_JOURNALRECORD:
583 case WH_JOURNALPLAYBACK:
584 case WH_MOUSE:
585 case WH_DEBUG:
586 SEGPTR_FREE( PTR_SEG_TO_LIN(lParam) );
587 break;
588
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000589 case WH_CALLWNDPROC:
590 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000591 LPCWPSTRUCT16 lpcwp16 = (LPCWPSTRUCT16)PTR_SEG_TO_LIN(lParam);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000592 LPCWPSTRUCT lpcwp32 = (LPCWPSTRUCT)lParamOrig;
Patrik Stridvall0f8bc5b1999-04-22 16:27:50 +0000593 MSGPARAM16 mp16;
594
595 mp16.wParam = lpcwp16->wParam;
596 mp16.lParam = lpcwp16->lParam;
597 mp16.lResult = 0;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000598
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000599 if (bA) WINPROC_UnmapMsg32ATo16( lpcwp32->hwnd,lpcwp32->message, lpcwp32->wParam,
Alexandre Julliard77b99181997-09-14 17:17:23 +0000600 lpcwp32->lParam, &mp16 );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000601 else WINPROC_UnmapMsg32WTo16( lpcwp32->hwnd,lpcwp32->message, lpcwp32->wParam,
Alexandre Julliard77b99181997-09-14 17:17:23 +0000602 lpcwp32->lParam, &mp16 );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000603 SEGPTR_FREE( PTR_SEG_TO_LIN(lParam) );
604 break;
605 }
606
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000607 case WH_GETMESSAGE:
608 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000609 LPMSG lpmsg32 = (LPMSG)lParamOrig;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000610
611 STRUCT32_MSG16to32( (LPMSG16)PTR_SEG_TO_LIN(lParam), lpmsg32 );
612 SEGPTR_FREE( PTR_SEG_TO_LIN(lParam) );
613 break;
614 }
615
616 case WH_CBT:
617 switch (code)
618 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000619 case HCBT_CREATEWND:
620 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000621 LPCBT_CREATEWNDA lpcbtcw32 = (LPCBT_CREATEWNDA)(lParamOrig);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000622 LPCBT_CREATEWND16 lpcbtcw16 = PTR_SEG_TO_LIN(lParam);
623 LPCREATESTRUCT16 lpcs16 = PTR_SEG_TO_LIN(lpcbtcw16->lpcs);
624
625 if (HIWORD(lpcs16->lpszName))
626 SEGPTR_FREE( PTR_SEG_TO_LIN(lpcs16->lpszName) );
627
628 if (HIWORD(lpcs16->lpszClass))
629 SEGPTR_FREE( PTR_SEG_TO_LIN(lpcs16->lpszClass) );
630
631 lpcbtcw32->hwndInsertAfter = lpcbtcw16->hwndInsertAfter;
632
633 SEGPTR_FREE( lpcs16 );
634 } /* fall through */
635
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000636 case HCBT_ACTIVATE:
637 case HCBT_CLICKSKIPPED:
638 case HCBT_MOVESIZE:
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000639
640 SEGPTR_FREE( PTR_SEG_TO_LIN(lParam) );
641 break;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000642 }
643 break;
644
645 case WH_SHELL:
646 case WH_KEYBOARD:
647 break;
648
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000649 case WH_HARDWARE:
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000650 case WH_FOREGROUNDIDLE:
651 case WH_CALLWNDPROCRET:
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000652 FIXME("\t[%i] skipping unmap\n", id);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000653 }
654}
655
656
657/***********************************************************************
658 * HOOK_UnMap32ATo16
659 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000660static void HOOK_UnMap32ATo16(INT id, INT code, WPARAM wParamOrig,
661 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000662 LPARAM lParam)
663{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000664 HOOK_UnMap32To16Common( id, code, wParamOrig, lParamOrig, wParam,
665 lParam, TRUE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000666}
667
668
669/***********************************************************************
670 * HOOK_UnMap32WTo16
671 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000672static void HOOK_UnMap32WTo16(INT id, INT code, WPARAM wParamOrig,
673 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000674 LPARAM lParam)
675{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000676 HOOK_UnMap32To16Common( id, code, wParamOrig, lParamOrig, wParam,
677 lParam, FALSE );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000678}
679
680
681/***********************************************************************
682 * HOOK_Map32ATo32W
683 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000684static void HOOK_Map32ATo32W(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000685 LPARAM *plParam)
686{
687 if (id == WH_CBT && code == HCBT_CREATEWND)
688 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000689 LPCBT_CREATEWNDA lpcbtcwA = (LPCBT_CREATEWNDA)*plParam;
Alexandre Julliard90476d62000-02-16 22:47:24 +0000690 LPCBT_CREATEWNDW lpcbtcwW = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000691 sizeof(*lpcbtcwW) );
Alexandre Julliard90476d62000-02-16 22:47:24 +0000692 lpcbtcwW->lpcs = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpcbtcwW->lpcs) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000693
694 lpcbtcwW->hwndInsertAfter = lpcbtcwA->hwndInsertAfter;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000695 *lpcbtcwW->lpcs = *(LPCREATESTRUCTW)lpcbtcwA->lpcs;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000696
697 if (HIWORD(lpcbtcwA->lpcs->lpszName))
698 {
Alexandre Julliard90476d62000-02-16 22:47:24 +0000699 lpcbtcwW->lpcs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000700 lpcbtcwA->lpcs->lpszName );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000701 }
702 else
703 lpcbtcwW->lpcs->lpszName = (LPWSTR)lpcbtcwA->lpcs->lpszName;
704
705 if (HIWORD(lpcbtcwA->lpcs->lpszClass))
706 {
Alexandre Julliard90476d62000-02-16 22:47:24 +0000707 lpcbtcwW->lpcs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000708 lpcbtcwA->lpcs->lpszClass );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000709 }
710 else
711 lpcbtcwW->lpcs->lpszClass = (LPCWSTR)lpcbtcwA->lpcs->lpszClass;
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000712 *plParam = (LPARAM)lpcbtcwW;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000713 }
714 return;
715}
716
717
718/***********************************************************************
719 * HOOK_UnMap32ATo32W
720 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000721static void HOOK_UnMap32ATo32W(INT id, INT code, WPARAM wParamOrig,
722 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000723 LPARAM lParam)
724{
725 if (id == WH_CBT && code == HCBT_CREATEWND)
726 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000727 LPCBT_CREATEWNDW lpcbtcwW = (LPCBT_CREATEWNDW)lParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000728 if (HIWORD(lpcbtcwW->lpcs->lpszName))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000729 HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcwW->lpcs->lpszName );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000730 if (HIWORD(lpcbtcwW->lpcs->lpszClass))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000731 HeapFree( GetProcessHeap(), 0, (LPWSTR)lpcbtcwW->lpcs->lpszClass );
732 HeapFree( GetProcessHeap(), 0, lpcbtcwW->lpcs );
733 HeapFree( GetProcessHeap(), 0, lpcbtcwW );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000734 }
735 return;
736}
737
738
739/***********************************************************************
740 * HOOK_Map32WTo32A
741 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000742static void HOOK_Map32WTo32A(INT id, INT code, WPARAM *pwParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000743 LPARAM *plParam)
744{
745 if (id == WH_CBT && code == HCBT_CREATEWND)
746 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000747 LPCBT_CREATEWNDW lpcbtcwW = (LPCBT_CREATEWNDW)*plParam;
Alexandre Julliard90476d62000-02-16 22:47:24 +0000748 LPCBT_CREATEWNDA lpcbtcwA = HeapAlloc( GetProcessHeap(), 0,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000749 sizeof(*lpcbtcwA) );
Alexandre Julliard90476d62000-02-16 22:47:24 +0000750 lpcbtcwA->lpcs = HeapAlloc( GetProcessHeap(), 0, sizeof(*lpcbtcwA->lpcs) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000751
752 lpcbtcwA->hwndInsertAfter = lpcbtcwW->hwndInsertAfter;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000753 *lpcbtcwA->lpcs = *(LPCREATESTRUCTA)lpcbtcwW->lpcs;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000754
755 if (HIWORD(lpcbtcwW->lpcs->lpszName))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000756 lpcbtcwA->lpcs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000757 lpcbtcwW->lpcs->lpszName );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000758 else
759 lpcbtcwA->lpcs->lpszName = (LPSTR)lpcbtcwW->lpcs->lpszName;
760
761 if (HIWORD(lpcbtcwW->lpcs->lpszClass))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000762 lpcbtcwA->lpcs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000763 lpcbtcwW->lpcs->lpszClass );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000764 else
765 lpcbtcwA->lpcs->lpszClass = (LPSTR)lpcbtcwW->lpcs->lpszClass;
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000766 *plParam = (LPARAM)lpcbtcwA;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000767 }
768 return;
769}
770
771
772/***********************************************************************
773 * HOOK_UnMap32WTo32A
774 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000775static void HOOK_UnMap32WTo32A(INT id, INT code, WPARAM wParamOrig,
776 LPARAM lParamOrig, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000777 LPARAM lParam)
778{
779 if (id == WH_CBT && code == HCBT_CREATEWND)
780 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000781 LPCBT_CREATEWNDA lpcbtcwA = (LPCBT_CREATEWNDA)lParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000782 if (HIWORD(lpcbtcwA->lpcs->lpszName))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000783 HeapFree( GetProcessHeap(), 0, (LPSTR)lpcbtcwA->lpcs->lpszName );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000784 if (HIWORD(lpcbtcwA->lpcs->lpszClass))
Alexandre Julliard90476d62000-02-16 22:47:24 +0000785 HeapFree( GetProcessHeap(), 0, (LPSTR)lpcbtcwA->lpcs->lpszClass );
786 HeapFree( GetProcessHeap(), 0, lpcbtcwA->lpcs );
787 HeapFree( GetProcessHeap(), 0, lpcbtcwA );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000788 }
789 return;
790}
791
792
793/***********************************************************************
794 * Map Function Tables
795 */
796static const HOOK_MapFunc HOOK_MapFuncs[3][3] =
797{
798 { NULL, HOOK_Map16To32A, HOOK_Map16To32W },
799 { HOOK_Map32ATo16, NULL, HOOK_Map32ATo32W },
800 { HOOK_Map32WTo16, HOOK_Map32WTo32A, NULL }
801};
802
803static const HOOK_UnMapFunc HOOK_UnMapFuncs[3][3] =
804{
805 { NULL, HOOK_UnMap16To32A, HOOK_UnMap16To32W },
806 { HOOK_UnMap32ATo16, NULL, HOOK_UnMap32ATo32W },
807 { HOOK_UnMap32WTo16, HOOK_UnMap32WTo32A, NULL }
808};
809
810
811/***********************************************************************
812 * Internal Functions
813 */
Alexandre Julliard58199531994-04-21 01:20:00 +0000814
Alexandre Julliardade697e1995-11-26 13:59:11 +0000815/***********************************************************************
816 * HOOK_GetNextHook
817 *
818 * Get the next hook of a given hook.
819 */
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000820static HANDLE16 HOOK_GetNextHook( HANDLE16 hook )
Alexandre Julliardade697e1995-11-26 13:59:11 +0000821{
822 HOOKDATA *data = (HOOKDATA *)USER_HEAP_LIN_ADDR( hook );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000823
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000824 if (!data || !hook) return 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000825 if (data->next) return data->next;
826 if (!data->ownerQueue) return 0; /* Already system hook */
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000827
Alexandre Julliardade697e1995-11-26 13:59:11 +0000828 /* Now start enumerating the system hooks */
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000829 return HOOK_systemHooks[data->id - WH_MINHOOK];
Alexandre Julliardade697e1995-11-26 13:59:11 +0000830}
831
832
833/***********************************************************************
834 * HOOK_GetHook
835 *
836 * Get the first hook for a given type.
837 */
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000838static HANDLE16 HOOK_GetHook( INT16 id, HQUEUE16 hQueue )
Alexandre Julliardade697e1995-11-26 13:59:11 +0000839{
840 MESSAGEQUEUE *queue;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000841 HANDLE16 hook = 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000842
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000843 if ((queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue )) != NULL)
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000844 hook = queue->hooks[id - WH_MINHOOK];
845 if (!hook) hook = HOOK_systemHooks[id - WH_MINHOOK];
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000846
847 QUEUE_Unlock( queue );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000848 return hook;
849}
850
851
852/***********************************************************************
853 * HOOK_SetHook
854 *
855 * Install a given hook.
856 */
Ulrich Weigandf4edf231999-09-20 18:45:00 +0000857/* ### start build ### */
858extern LONG CALLBACK HOOK_CallTo16_long_wwl(FARPROC16,WORD,WORD,LONG);
859/* ### stop build ### */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000860static HHOOK HOOK_SetHook( INT16 id, LPVOID proc, INT type,
Ulrich Weiganda8975181999-01-20 13:11:45 +0000861 HMODULE16 hModule, DWORD dwThreadId )
Alexandre Julliardade697e1995-11-26 13:59:11 +0000862{
863 HOOKDATA *data;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000864 HANDLE16 handle;
865 HQUEUE16 hQueue = 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000866
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000867 if ((id < WH_MINHOOK) || (id > WH_MAXHOOK)) return 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000868
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000869 TRACE("Setting hook %d: %08x %04x %08lx\n",
Alexandre Julliarda3960291999-02-26 11:11:13 +0000870 id, (UINT)proc, hModule, dwThreadId );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000871
Ulrich Weiganda8975181999-01-20 13:11:45 +0000872 /* Create task queue if none present */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000873 GetFastQueue16();
Alexandre Julliard77b99181997-09-14 17:17:23 +0000874
Alexandre Julliarda3960291999-02-26 11:11:13 +0000875 if (id == WH_JOURNALPLAYBACK) EnableHardwareInput16(FALSE);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000876
Ulrich Weiganda8975181999-01-20 13:11:45 +0000877 if (dwThreadId) /* Task-specific hook */
Alexandre Julliardade697e1995-11-26 13:59:11 +0000878 {
879 if ((id == WH_JOURNALRECORD) || (id == WH_JOURNALPLAYBACK) ||
880 (id == WH_SYSMSGFILTER)) return 0; /* System-only hooks */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000881 if (!(hQueue = GetThreadQueue16( dwThreadId )))
Ulrich Weiganda8975181999-01-20 13:11:45 +0000882 return 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000883 }
884
Alexandre Julliardade697e1995-11-26 13:59:11 +0000885 /* Create the hook structure */
886
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000887 if (!(handle = USER_HEAP_ALLOC( sizeof(HOOKDATA) ))) return 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000888 data = (HOOKDATA *) USER_HEAP_LIN_ADDR( handle );
889 data->proc = proc;
890 data->id = id;
891 data->ownerQueue = hQueue;
Ulrich Weiganda8975181999-01-20 13:11:45 +0000892 data->ownerModule = hModule;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000893 data->flags = type;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000894
Ulrich Weigandf4edf231999-09-20 18:45:00 +0000895 /* Create CallTo16 thunk for 16-bit hooks */
896
897 if ( (data->flags & HOOK_MAPTYPE) == HOOK_WIN16 )
898 data->thunk = (HOOKPROC)THUNK_Alloc( (FARPROC16)data->proc,
899 (RELAY)HOOK_CallTo16_long_wwl );
900 else
901 data->thunk = data->proc;
902
903 if ( !data->thunk && data->proc )
904 {
905 USER_HEAP_FREE( handle );
906 return 0;
907 }
908
Alexandre Julliardade697e1995-11-26 13:59:11 +0000909 /* Insert it in the correct linked list */
910
911 if (hQueue)
912 {
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000913 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000914 data->next = queue->hooks[id - WH_MINHOOK];
915 queue->hooks[id - WH_MINHOOK] = handle;
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000916 QUEUE_Unlock( queue );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000917 }
918 else
919 {
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000920 data->next = HOOK_systemHooks[id - WH_MINHOOK];
921 HOOK_systemHooks[id - WH_MINHOOK] = handle;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000922 }
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000923 TRACE("Setting hook %d: ret=%04x [next=%04x]\n",
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000924 id, handle, data->next );
Ulrich Weiganda8975181999-01-20 13:11:45 +0000925
926 return (HHOOK)( handle? MAKELONG( handle, HOOK_MAGIC ) : 0 );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000927}
928
929
930/***********************************************************************
931 * HOOK_RemoveHook
932 *
933 * Remove a hook from the list.
934 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000935static BOOL HOOK_RemoveHook( HANDLE16 hook )
Alexandre Julliardade697e1995-11-26 13:59:11 +0000936{
937 HOOKDATA *data;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000938 HANDLE16 *prevHook;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000939
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000940 TRACE("Removing hook %04x\n", hook );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000941
942 if (!(data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook))) return FALSE;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000943 if (data->flags & HOOK_INUSE)
Alexandre Julliardade697e1995-11-26 13:59:11 +0000944 {
945 /* Mark it for deletion later on */
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000946 WARN("Hook still running, deletion delayed\n" );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000947 data->proc = (HOOKPROC)0;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000948 return TRUE;
949 }
950
Alexandre Julliarda3960291999-02-26 11:11:13 +0000951 if (data->id == WH_JOURNALPLAYBACK) EnableHardwareInput16(TRUE);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000952
Alexandre Julliardade697e1995-11-26 13:59:11 +0000953 /* Remove it from the linked list */
954
955 if (data->ownerQueue)
956 {
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000957 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( data->ownerQueue );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000958 if (!queue) return FALSE;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000959 prevHook = &queue->hooks[data->id - WH_MINHOOK];
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000960 QUEUE_Unlock( queue );
Alexandre Julliardade697e1995-11-26 13:59:11 +0000961 }
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000962 else prevHook = &HOOK_systemHooks[data->id - WH_MINHOOK];
Alexandre Julliardade697e1995-11-26 13:59:11 +0000963
964 while (*prevHook && *prevHook != hook)
965 prevHook = &((HOOKDATA *)USER_HEAP_LIN_ADDR(*prevHook))->next;
966
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000967 if (!*prevHook) return FALSE;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000968 *prevHook = data->next;
Ulrich Weigandf4edf231999-09-20 18:45:00 +0000969
970 if ( (data->flags & HOOK_MAPTYPE) == HOOK_WIN16 )
971 THUNK_Free( (FARPROC)data->thunk );
972
Alexandre Julliardade697e1995-11-26 13:59:11 +0000973 USER_HEAP_FREE( hook );
974 return TRUE;
975}
976
977
978/***********************************************************************
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000979 * HOOK_FindValidHook
980 */
981static HANDLE16 HOOK_FindValidHook( HANDLE16 hook )
982{
983 HOOKDATA *data;
984
985 for (;;)
986 {
987 if (!(data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook))) return 0;
988 if (data->proc) return hook;
989 hook = data->next;
990 }
991}
992
993
994/***********************************************************************
Alexandre Julliardade697e1995-11-26 13:59:11 +0000995 * HOOK_CallHook
996 *
997 * Call a hook procedure.
998 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000999static LRESULT HOOK_CallHook( HANDLE16 hook, INT fromtype, INT code,
1000 WPARAM wParam, LPARAM lParam )
Alexandre Julliardade697e1995-11-26 13:59:11 +00001001{
Alexandre Julliardade697e1995-11-26 13:59:11 +00001002 MESSAGEQUEUE *queue;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001003 HANDLE16 prevHook;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001004 HOOKDATA *data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook);
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001005 LRESULT ret;
Ulrich Weigand4b6b1c31999-05-17 14:55:30 +00001006 int iWndsLocks;
Alexandre Julliardade697e1995-11-26 13:59:11 +00001007
Alexandre Julliarda3960291999-02-26 11:11:13 +00001008 WPARAM wParamOrig = wParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001009 LPARAM lParamOrig = lParam;
1010 HOOK_MapFunc MapFunc;
1011 HOOK_UnMapFunc UnMapFunc;
Alexandre Julliardade697e1995-11-26 13:59:11 +00001012
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001013 MapFunc = HOOK_MapFuncs[fromtype][data->flags & HOOK_MAPTYPE];
1014 UnMapFunc = HOOK_UnMapFuncs[fromtype][data->flags & HOOK_MAPTYPE];
1015
1016 if (MapFunc)
1017 MapFunc( data->id, code, &wParam, &lParam );
Alexandre Julliardade697e1995-11-26 13:59:11 +00001018
1019 /* Now call it */
1020
Alexandre Julliarda3960291999-02-26 11:11:13 +00001021 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0;
Alexandre Julliardade697e1995-11-26 13:59:11 +00001022 prevHook = queue->hCurHook;
1023 queue->hCurHook = hook;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001024 data->flags |= HOOK_INUSE;
Alexandre Julliardade697e1995-11-26 13:59:11 +00001025
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001026 TRACE("Calling hook %04x: %d %08x %08lx\n",
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001027 hook, code, wParam, lParam );
1028
Ulrich Weigand4b6b1c31999-05-17 14:55:30 +00001029 /* Suspend window structure locks before calling user code */
1030 iWndsLocks = WIN_SuspendWndsLock();
1031
Ulrich Weigandf4edf231999-09-20 18:45:00 +00001032 ret = data->thunk(code, wParam, lParam);
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001033
Ulrich Weigand5b803351999-03-16 10:29:55 +00001034 /* Grrr. While the hook procedure is supposed to have an LRESULT return
1035 value even in Win16, it seems that for those hook types where the
1036 return value is interpreted as BOOL, Windows doesn't actually check
1037 the HIWORD ... Some buggy Win16 programs, notably WINFILE, rely on
1038 that, because they neglect to clear DX ... */
1039 if ( (data->flags & HOOK_MAPTYPE) == HOOK_WIN16
1040 && data->id != WH_JOURNALPLAYBACK )
1041 ret = LOWORD( ret );
1042
Ulrich Weigand4b6b1c31999-05-17 14:55:30 +00001043 WIN_RestoreWndsLock(iWndsLocks);
1044
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001045 TRACE("Ret hook %04x = %08lx\n", hook, ret );
Alexandre Julliardade697e1995-11-26 13:59:11 +00001046
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001047 data->flags &= ~HOOK_INUSE;
Alexandre Julliardade697e1995-11-26 13:59:11 +00001048 queue->hCurHook = prevHook;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001049
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001050 QUEUE_Unlock( queue );
1051
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001052 if (UnMapFunc)
1053 UnMapFunc( data->id, code, wParamOrig, lParamOrig, wParam, lParam );
1054
Alexandre Julliardade697e1995-11-26 13:59:11 +00001055 if (!data->proc) HOOK_RemoveHook( hook );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001056
Alexandre Julliardade697e1995-11-26 13:59:11 +00001057 return ret;
1058}
1059
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001060/***********************************************************************
1061 * Exported Functions & APIs
1062 */
1063
1064/***********************************************************************
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001065 * HOOK_IsHooked
1066 *
1067 * Replacement for calling HOOK_GetHook from other modules.
1068 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001069BOOL HOOK_IsHooked( INT16 id )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001070{
Ulrich Weiganda8975181999-01-20 13:11:45 +00001071 /* Hmmm. Use GetThreadQueue(0) instead of GetFastQueue() here to
1072 avoid queue being created if someone wants to merely check ... */
1073
Alexandre Julliarda3960291999-02-26 11:11:13 +00001074 return HOOK_GetHook( id, GetThreadQueue16(0) ) != 0;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001075}
1076
1077
1078/***********************************************************************
1079 * HOOK_CallHooks16
Alexandre Julliardade697e1995-11-26 13:59:11 +00001080 *
1081 * Call a hook chain.
1082 */
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001083LRESULT HOOK_CallHooks16( INT16 id, INT16 code, WPARAM16 wParam,
1084 LPARAM lParam )
Alexandre Julliardade697e1995-11-26 13:59:11 +00001085{
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001086 HANDLE16 hook;
1087
Alexandre Julliarda3960291999-02-26 11:11:13 +00001088 if (!(hook = HOOK_GetHook( id, GetFastQueue16() ))) return 0;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001089 if (!(hook = HOOK_FindValidHook(hook))) return 0;
1090 return HOOK_CallHook( hook, HOOK_WIN16, code, wParam, lParam );
1091}
1092
1093/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001094 * HOOK_CallHooksA
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001095 *
1096 * Call a hook chain.
1097 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001098LRESULT HOOK_CallHooksA( INT id, INT code, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001099 LPARAM lParam )
1100{
1101 HANDLE16 hook;
1102
Alexandre Julliarda3960291999-02-26 11:11:13 +00001103 if (!(hook = HOOK_GetHook( id, GetFastQueue16() ))) return 0;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001104 if (!(hook = HOOK_FindValidHook(hook))) return 0;
Alexandre Julliard349a9531997-02-02 19:01:52 +00001105 return HOOK_CallHook( hook, HOOK_WIN32A, code, wParam, lParam );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001106}
1107
1108/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001109 * HOOK_CallHooksW
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001110 *
1111 * Call a hook chain.
1112 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001113LRESULT HOOK_CallHooksW( INT id, INT code, WPARAM wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001114 LPARAM lParam )
1115{
1116 HANDLE16 hook;
1117
Alexandre Julliarda3960291999-02-26 11:11:13 +00001118 if (!(hook = HOOK_GetHook( id, GetFastQueue16() ))) return 0;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001119 if (!(hook = HOOK_FindValidHook(hook))) return 0;
Alexandre Julliard349a9531997-02-02 19:01:52 +00001120 return HOOK_CallHook( hook, HOOK_WIN32W, code, wParam,
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001121 lParam );
Alexandre Julliardade697e1995-11-26 13:59:11 +00001122}
Alexandre Julliard58199531994-04-21 01:20:00 +00001123
1124
1125/***********************************************************************
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001126 * HOOK_ResetQueueHooks
1127 */
1128void HOOK_ResetQueueHooks( HQUEUE16 hQueue )
1129{
1130 MESSAGEQUEUE *queue;
1131
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001132 if ((queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue )) != NULL)
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001133 {
1134 HOOKDATA* data;
1135 HHOOK hook;
1136 int id;
1137 for( id = WH_MINHOOK; id <= WH_MAXHOOK; id++ )
1138 {
1139 hook = queue->hooks[id - WH_MINHOOK];
1140 while( hook )
1141 {
1142 if( (data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook)) )
1143 {
1144 data->ownerQueue = hQueue;
1145 hook = data->next;
1146 } else break;
1147 }
1148 }
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001149
1150 QUEUE_Unlock( queue );
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001151 }
1152}
1153
1154/***********************************************************************
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001155 * HOOK_FreeModuleHooks
1156 */
Alexandre Julliard3051b641996-07-05 17:14:13 +00001157void HOOK_FreeModuleHooks( HMODULE16 hModule )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001158{
1159 /* remove all system hooks registered by this module */
1160
1161 HOOKDATA* hptr;
1162 HHOOK hook, next;
1163 int id;
1164
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001165 for( id = WH_MINHOOK; id <= WH_MAXHOOK; id++ )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001166 {
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001167 hook = HOOK_systemHooks[id - WH_MINHOOK];
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001168 while( hook )
1169 if( (hptr = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook)) )
1170 {
1171 next = hptr->next;
1172 if( hptr->ownerModule == hModule )
1173 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001174 hptr->flags &= HOOK_MAPTYPE;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001175 HOOK_RemoveHook(hook);
1176 }
1177 hook = next;
1178 }
1179 else hook = 0;
1180 }
1181}
1182
1183/***********************************************************************
1184 * HOOK_FreeQueueHooks
1185 */
Alexandre Julliard3051b641996-07-05 17:14:13 +00001186void HOOK_FreeQueueHooks( HQUEUE16 hQueue )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001187{
1188 /* remove all hooks registered by this queue */
1189
1190 HOOKDATA* hptr = NULL;
1191 HHOOK hook, next;
1192 int id;
1193
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001194 for( id = WH_MINHOOK; id <= WH_MAXHOOK; id++ )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001195 {
1196 hook = HOOK_GetHook( id, hQueue );
1197 while( hook )
1198 {
1199 next = HOOK_GetNextHook(hook);
1200
1201 hptr = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook);
1202 if( hptr && hptr->ownerQueue == hQueue )
1203 {
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001204 hptr->flags &= HOOK_MAPTYPE;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001205 HOOK_RemoveHook(hook);
1206 }
1207 hook = next;
1208 }
1209 }
1210}
1211
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001212
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001213/***********************************************************************
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001214 * SetWindowsHook16 (USER.121)
Alexandre Julliard58199531994-04-21 01:20:00 +00001215 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001216FARPROC16 WINAPI SetWindowsHook16( INT16 id, HOOKPROC16 proc )
Alexandre Julliard58199531994-04-21 01:20:00 +00001217{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001218 HINSTANCE16 hInst = FarGetOwner16( HIWORD(proc) );
Alexandre Julliardade697e1995-11-26 13:59:11 +00001219
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001220 /* WH_MSGFILTER is the only task-specific hook for SetWindowsHook() */
1221 HTASK16 hTask = (id == WH_MSGFILTER) ? GetCurrentTask() : 0;
1222
Ulrich Weiganda8975181999-01-20 13:11:45 +00001223 return (FARPROC16)SetWindowsHookEx16( id, proc, hInst, hTask );
Alexandre Julliard58199531994-04-21 01:20:00 +00001224}
1225
Alexandre Julliard58199531994-04-21 01:20:00 +00001226/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001227 * SetWindowsHookA (USER32.525)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001228 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001229HHOOK WINAPI SetWindowsHookA( INT id, HOOKPROC proc )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001230{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001231 return SetWindowsHookExA( id, proc, 0, GetCurrentThreadId() );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001232}
1233
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001234/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001235 * SetWindowsHookW (USER32.528)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001236 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001237HHOOK WINAPI SetWindowsHookW( INT id, HOOKPROC proc )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001238{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001239 return SetWindowsHookExW( id, proc, 0, GetCurrentThreadId() );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001240}
1241
1242
1243/***********************************************************************
1244 * SetWindowsHookEx16 (USER.291)
1245 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001246HHOOK WINAPI SetWindowsHookEx16( INT16 id, HOOKPROC16 proc, HINSTANCE16 hInst,
1247 HTASK16 hTask )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001248{
Ulrich Weiganda8975181999-01-20 13:11:45 +00001249 if (id == WH_DEBUG)
1250 {
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001251 FIXME("WH_DEBUG is broken in 16-bit Windows.\n");
Ulrich Weiganda8975181999-01-20 13:11:45 +00001252 return 0;
1253 }
1254 return HOOK_SetHook( id, proc, HOOK_WIN16, GetExePtr(hInst), (DWORD)hTask );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001255}
1256
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001257/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001258 * SetWindowsHookExA (USER32.526)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001259 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001260HHOOK WINAPI SetWindowsHookExA( INT id, HOOKPROC proc, HINSTANCE hInst,
Ulrich Weiganda8975181999-01-20 13:11:45 +00001261 DWORD dwThreadId )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001262{
Ulrich Weiganda8975181999-01-20 13:11:45 +00001263 return HOOK_SetHook( id, proc, HOOK_WIN32A, MapHModuleLS(hInst), dwThreadId );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001264}
1265
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001266/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001267 * SetWindowsHookExW (USER32.527)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001268 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001269HHOOK WINAPI SetWindowsHookExW( INT id, HOOKPROC proc, HINSTANCE hInst,
Ulrich Weiganda8975181999-01-20 13:11:45 +00001270 DWORD dwThreadId )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001271{
Ulrich Weiganda8975181999-01-20 13:11:45 +00001272 return HOOK_SetHook( id, proc, HOOK_WIN32W, MapHModuleLS(hInst), dwThreadId );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001273}
1274
1275
1276/***********************************************************************
Alexandre Julliardbf9130a1996-10-13 17:45:47 +00001277 * UnhookWindowsHook16 (USER.234)
Alexandre Julliard58199531994-04-21 01:20:00 +00001278 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001279BOOL16 WINAPI UnhookWindowsHook16( INT16 id, HOOKPROC16 proc )
Alexandre Julliard58199531994-04-21 01:20:00 +00001280{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001281 return UnhookWindowsHook( id, (HOOKPROC)proc );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001282}
1283
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001284/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001285 * UnhookWindowsHook (USER32.557)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001286 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001287BOOL WINAPI UnhookWindowsHook( INT id, HOOKPROC proc )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001288{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001289 HANDLE16 hook = HOOK_GetHook( id, GetFastQueue16() );
Alexandre Julliard594997c1995-04-30 10:05:20 +00001290
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001291 TRACE("%d %08lx\n", id, (DWORD)proc );
Alexandre Julliardade697e1995-11-26 13:59:11 +00001292
1293 while (hook)
1294 {
1295 HOOKDATA *data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook);
1296 if (data->proc == proc) break;
1297 hook = HOOK_GetNextHook( hook );
Alexandre Julliard594997c1995-04-30 10:05:20 +00001298 }
Alexandre Julliardade697e1995-11-26 13:59:11 +00001299 if (!hook) return FALSE;
1300 return HOOK_RemoveHook( hook );
Alexandre Julliard58199531994-04-21 01:20:00 +00001301}
1302
1303
1304/***********************************************************************
Patrik Stridvall54fe8382000-04-06 20:21:16 +00001305 * UnhookWindowsHookEx16 (USER.292)
Alexandre Julliard58199531994-04-21 01:20:00 +00001306 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001307BOOL16 WINAPI UnhookWindowsHookEx16( HHOOK hhook )
Alexandre Julliard58199531994-04-21 01:20:00 +00001308{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001309 return UnhookWindowsHookEx( hhook );
Alexandre Julliard58199531994-04-21 01:20:00 +00001310}
1311
Alexandre Julliard58199531994-04-21 01:20:00 +00001312/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001313 * UnhookWindowsHookEx (USER32.558)
Alexandre Julliard58199531994-04-21 01:20:00 +00001314 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001315BOOL WINAPI UnhookWindowsHookEx( HHOOK hhook )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001316{
Ulrich Weiganda8975181999-01-20 13:11:45 +00001317 if (HIWORD(hhook) != HOOK_MAGIC) return FALSE; /* Not a new format hook */
1318 return HOOK_RemoveHook( LOWORD(hhook) );
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001319}
1320
1321
1322/***********************************************************************
1323 * CallNextHookEx16 (USER.293)
1324 *
1325 * I wouldn't have separated this into 16 and 32 bit versions, but I
1326 * need a way to figure out if I need to do a mapping or not.
1327 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001328LRESULT WINAPI CallNextHookEx16( HHOOK hhook, INT16 code, WPARAM16 wParam,
1329 LPARAM lParam )
Alexandre Julliard58199531994-04-21 01:20:00 +00001330{
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001331 HANDLE16 next;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001332
Alexandre Julliardade697e1995-11-26 13:59:11 +00001333 if (HIWORD(hhook) != HOOK_MAGIC) return 0; /* Not a new format hook */
1334 if (!(next = HOOK_GetNextHook( LOWORD(hhook) ))) return 0;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001335
1336 return HOOK_CallHook( next, HOOK_WIN16, code, wParam, lParam );
1337}
1338
1339
1340/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001341 * CallNextHookEx (USER32.17)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001342 *
1343 * There aren't ANSI and UNICODE versions of this.
1344 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001345LRESULT WINAPI CallNextHookEx( HHOOK hhook, INT code, WPARAM wParam,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001346 LPARAM lParam )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001347{
1348 HANDLE16 next;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001349 INT fromtype; /* figure out Ansi/Unicode */
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001350 HOOKDATA *oldhook;
1351
1352 if (HIWORD(hhook) != HOOK_MAGIC) return 0; /* Not a new format hook */
1353 if (!(next = HOOK_GetNextHook( LOWORD(hhook) ))) return 0;
1354
1355 oldhook = (HOOKDATA *)USER_HEAP_LIN_ADDR( LOWORD(hhook) );
1356 fromtype = oldhook->flags & HOOK_MAPTYPE;
1357
Alexandre Julliard349a9531997-02-02 19:01:52 +00001358 if (fromtype == HOOK_WIN16)
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001359 ERR("called from 16bit hook!\n");
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001360
1361 return HOOK_CallHook( next, fromtype, code, wParam, lParam );
1362}
1363
1364
1365/***********************************************************************
1366 * DefHookProc16 (USER.235)
1367 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001368LRESULT WINAPI DefHookProc16( INT16 code, WPARAM16 wParam, LPARAM lParam,
1369 HHOOK *hhook )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001370{
1371 /* Note: the *hhook parameter is never used, since we rely on the
1372 * current hook value from the task queue to find the next hook. */
1373 MESSAGEQUEUE *queue;
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001374 LRESULT ret;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001375
Alexandre Julliarda3960291999-02-26 11:11:13 +00001376 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0;
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001377 ret = CallNextHookEx16( queue->hCurHook, code, wParam, lParam );
1378 QUEUE_Unlock( queue );
1379 return ret;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001380}
1381
1382
1383/***********************************************************************
1384 * CallMsgFilter16 (USER.123)
1385 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001386BOOL16 WINAPI CallMsgFilter16( SEGPTR msg, INT16 code )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001387{
1388 if (GetSysModalWindow16()) return FALSE;
1389 if (HOOK_CallHooks16( WH_SYSMSGFILTER, code, 0, (LPARAM)msg )) return TRUE;
1390 return HOOK_CallHooks16( WH_MSGFILTER, code, 0, (LPARAM)msg );
1391}
1392
1393
1394/***********************************************************************
Patrik Stridvall54fe8382000-04-06 20:21:16 +00001395 * CallMsgFilter32 (USER.823)
Andreas Mohr94e44851999-01-23 14:15:17 +00001396 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001397BOOL16 WINAPI CallMsgFilter32_16( SEGPTR msg16_32, INT16 code, BOOL16 wHaveParamHigh )
Andreas Mohr94e44851999-01-23 14:15:17 +00001398{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001399 MSG32_16 *lpmsg16_32 = (MSG32_16 *)PTR_SEG_TO_LIN(msg16_32);
Andreas Mohr94e44851999-01-23 14:15:17 +00001400
1401 if (wHaveParamHigh == FALSE)
1402 {
1403 lpmsg16_32->wParamHigh = 0;
1404 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1405 return CallMsgFilter16(msg16_32, code);
1406 }
1407 else
1408 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001409 MSG msg32;
Andreas Mohr94e44851999-01-23 14:15:17 +00001410 BOOL16 ret;
1411
1412 msg32.hwnd = lpmsg16_32->msg.hwnd;
1413 msg32.message = lpmsg16_32->msg.message;
1414 msg32.wParam =
1415 MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
1416 msg32.lParam = lpmsg16_32->msg.lParam;
1417 msg32.time = lpmsg16_32->msg.time;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001418 msg32.pt.x = (INT)lpmsg16_32->msg.pt.x;
1419 msg32.pt.y = (INT)lpmsg16_32->msg.pt.y;
Andreas Mohr94e44851999-01-23 14:15:17 +00001420
Alexandre Julliarda3960291999-02-26 11:11:13 +00001421 ret = (BOOL16)CallMsgFilterA(&msg32, (INT)code);
Andreas Mohr94e44851999-01-23 14:15:17 +00001422
1423 lpmsg16_32->msg.hwnd = msg32.hwnd;
1424 lpmsg16_32->msg.message = msg32.message;
1425 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1426 lpmsg16_32->msg.lParam = msg32.lParam;
1427 lpmsg16_32->msg.time = msg32.time;
1428 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1429 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1430 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1431
1432 return ret;
1433 }
1434}
1435
1436
1437/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +00001438 * CallMsgFilterA (USER32.15)
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001439 */
1440/*
1441 * 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 Stridvall2d6457c2000-03-28 20:22:59 +00001454 * CallMsgFilterW (USER32.16)
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