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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access