INF: Importance of Calling DefHookProc()

ID Number: Q74547

3.00

WINDOWS

Summary:

When an application installs a hook using SetWindowsHook, Windows

adds the hook's callback filter function to the hook chain. It is

the responsibility of each callback function to call the next

function in the chain. DefHookProc() is used to call the next

function in the hook chain.

More Information:

If a callback function does not call DefHookProc(), none of the

filter functions that were installed before the current filter will

be called. Windows will try to process the message and this could

hang the system.

Only a keyboard hook (WH_KEYBOARD) can suppress a keyboard event by

not calling DefHookProc and returning a 1. When the system gets a

value of 1 from a keyboard hook callback function, it discards the

message.

Furthermore, when the hook callback function receives a negative value

for the nCode parameter, it should pass the message and the parameters

to DefHookProc() without further processing. When nCode is negative,

Windows is in the process of removing a hook callback function from

the hook chain.