Microsoft KB Archive/92659

{|
 * width="100%"|

PRB: SetWindowsHookEx Fails to Install Task-Specific Filter

 * }

Q92659

-

The information in this article applies to:


 * Microsoft Windows Software Development Kit (SDK) 3.1

-

SYMPTOMS
In Windows version 3.1, the SetWindowsHookEx function fails when it is called to install a task-specific filter (hook) that resides in a DLL.

CAUSE
According 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.

RESOLUTION
To 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( &quot;HOOK.DLL&quot; ),                   hTargetTask ); This resolution is compatible with future versions of Windows.

Additional query words: hook not allowed

Keywords : _IK kb16bitonly kbHook kbGrpDSUser kbOSWin310

Issue type : kbprb

Technology : kbAudDeveloper kbWin3xSearch kbSDKSearch kbWinSDKSearch kbWinSDK310