• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 619
  • Last Modified:

Can WH_DEBUG hook detect when a hook is uninstalled

I know that WH_DEBUG can detect when a hook is installed.  Does anybody know whether it can also detect when a hook is uninstalled?  If so, can you point me to a code sample which does such detection.  Thanks...
  • 3
2 Solutions
I don't think so. And I don't think it can detect when a hook is installed.
MSDN states :
The system calls a WH_DEBUG hook procedure before calling hook procedures associated with any other hook in the system. You can use this hook to determine whether to allow the system to call hook procedures associated with other types of hooks."

So nothing about (un)installation of a hook.
I think you were missleaded by what says the MSDN for DebugProc wParam parameter (which I'm positive it's a copy-paste of the table from SetWindowsHookEx.. :)
you can do the following:

install a normal global hook
which, of course, involves that your dll is loaded in every app
your dll then, in its initialization code, replaces the normal UnhookWindowsHookEx by a
routine of the same signature which calls the "real" unhookwindowshookex proc but
also places a notification record in a shared memory section of your dll.
this record will then be read periodically by a thread in your application.

the whole thing is a little bit complicated, but it would work, maybe.
DanFromBostonAuthor Commented:
That's an interesting idea.  Are you sure that when you install a global hook that it's loaded into every app on the system?  I thought it was just loaded in the context of the thread you specify.

dwThreadId "If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread."
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now