PRB: SetWindowsHookEx() Fails to Install Task-Specific FilterLast reviewed: November 2, 1995Article ID: Q92659 |
The information in this article applies to:
SYMPTOMSIn Windows version 3.1, the SetWindowsHookEx() function fails when it is called to install a task-specific filter (hook) that resides in a DLL.
CAUSEAccording to the documentation, the third parameter to the SetWindowsHookEx() function must be the instance handle of the application or the DLL that contains the filter function. However, because of a problem in Windows 3.1, the SetWindowsHookEx() function fails when it is called to install a task-specific filter using the DLL's instance handle. Note that such a problem does not exist when the SetWindowsHookEx() function is called to install a system-wide filter in a DLL. The DLL's instance handle is accepted as a valid parameter. The first argument passed to the LibMain function of a DLL contains its instance handle.
RESOLUTIONTo install a task-specific filter that resides in a DLL, pass the module handle of the DLL as the third parameter to the SetWindowsHookEx() function. The module handle can be retrieved using the GetModuleHandle() function. For example, to install a task-specific keyboard filter, the code might resemble the following: g_hHook = SetWindowsHookEx( WH_KEYBOARD, HookCallbackProc, GetModuleHandle( "HOOK.DLL" ), hTargetTask );This resolution is compatible with future versions of Windows.
|
Additional reference words: 3.10 3.50 3.51 4.00 95 hook not allowed
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |