Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote a system hook dll that monitors windows messages in another application. Everything works except it takes a long time for the hook dll to go away after my application exited. This is annoying because I can not build my projects as often. I noticed that the hook dll is injected to more than 30 applications on my XP windows. The first 10 plus applications release the hook dll as soon as my application exited. But the rest of the applications release the hook dll at 5-10 minutes later.

My question is: is there a way to speed up the unloading of the hook dll after calling UnhookWindowsHookEx()? or is there a way to write a system hook dll that only injects into a particular application that I am interested?

Thanks
Posted

1 solution

There must be something in your code that is holding up the DLL.
You could try to comment out all code in the hook callback and check if this happens.

Using SetWindowsHookEx you can either hook into the current process or all processes. You need other techniques to only hook into selected processes.

Here are some good articles on hooking -
Three Ways to Inject Your Code into Another Process[^]
API Hooking Revealed[^]
A More Complete DLL Injection Solution Using CreateRemoteThread[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900