Caveats
As with the WH_CALLWNDPROC
hook, the main thing
to
remember is that this hook captures only messages that are sent using
the SendMessage function. This function will not
capture messages that are posted to the message queue using the
PostMessage function. In the case of posted
messages, you should use the WH_GETMESSAGE
hook;
this hook is discussed in Chapter 11.
The other thing to remember is that this hook captures messages after
the window procedure has processed the message. The
WH_CALLWNDPROC
hook captures the sent message
before the window procedure has processed it.
Take care when using any hook because performance can be seriously degraded. Using a thread-specific hook can degrade performance for a single thread because it operates from within that thread only. A system-wide hook resides in a DLL that is injected into all running processes. Therefore, if the hook’s filter function code puts undue strain on the system, every thread in the system can slow to a crawl. This causes the entire system to act sluggishly. When writing filter functions for hooks of either scope, you should exit the code as early as possible. By this I mean that if the hook intercepts messages that are of no interest, you should exit the filter function immediately.
Get Subclassing and Hooking with Visual Basic now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.