Click here to Skip to main content
15,440,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

We are hooking TextOut(),ExtTextOut() and DrawText() methods GLOBALLY .

i.e.
hhook = SetWindowsHookEx(WH_CBT, function_address, module_handle, 0);

But we want to hook/unhook only a particular exe. Can someone tell us how to check all the existing threads and get the required exe and hook/unhook only that.

Please provide help.

Thank you
Posted
Updated 24-Jun-22 1:57am

A couple of things wrong with this thread and I mean TOTALLY wrong.
You can not 'hook' functions per se with the SetWindowsHookEx function rather this function lets you intercept Windows messages of a particular Window(thread), before or after or both, and do something with them or simply observe them.

The prototype shown by helpseeker123 here confuses the parameter 'function_address' to being the function address of a function like TextOut()
which it is not but rather Windows specific callback functions clearly described in the documentation of SetWindowsHookEx for each specific type of hook.

hhook = SetWindowsHookEx(WH_CBT, function_address, module_handle, 0);

If you hook another application to intercept its messages by using SetWindowsHookEx and if your callback function_address resides in a dll then SetWindowsHookEx function will 'inject' (load) that dll into that application where your dll can then 'subclass' ( or 'super-class') windows procedures in that application, the application's or any of its children windows and controls.

When your dll is in the hooked application's address space it can even replace that application's function calls to any other dll, provided you know its prototype, and I guess it is this type of hooking helpseeker123 is interested in.

One simple method of doing it is using SetWindowsHookEx but just to make it inject your dll in the other application. Countless articles and sample code already exist.

A second method would be to use Microsoft's own Detours library package (free) that claims to streamline this process. It took me about 10 minutes before I threw it out the window in favor of SetWindowHooksEx.

The Windows shell also provides hooking and detouring functions but which I have never used and so can not claim on their merits.

Many more are out there, try googling for 'similar to microsoft detours' and you will see them.
 
Share this answer
 
Can you show me how you are hooking the TextOut(),ExtTextOut() and DrawText() methods? I am needing to do the same thing, and do not know how.
 
Share this answer
 
You may also call GetModuleFileName [^] and act accordingly.
:)
 
Share this answer
 
v2
If you want to find the exe you don't have to check all threads. You just need to enumerate the processes. Hope the article Enumerating All Processes[^] in MSDN will help you.
 
Share this answer
 

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