Reputation: 1348
I am trying to hook an API (say, MessageBox()) in other processes (I may not know the process ID) on Windows, I know that I have to use the SetWindowsHookEx() function. But still, I have three questions:
1) Can SetWindowsHookEx() function makes the hook global, i.e., not limited to current process? (When ther applications call this API, it is hooked?)
2) If I want to replace the to-be-hooked API with my own function, how should I do?
3) I read many materials, and I found the term "hook procedure" or "hook function". How should I comprehend this? Currently, I take it as the function that I will use to replace the API (say again, MessageBox).
Upvotes: 2
Views: 3905
Reputation: 2813
You can use Deviare API Hook for this. With this library you can hook any API in 10 lines of code even with .NET The difference with Detours is that you don't have to write the code that is inserted in each process. You can hook all the processes you want just attaching them. Then, you receive the calls in your own process.
Upvotes: 1
Reputation: 36906
This is not what SetWindowsHookEx
is for. SetWindowsHookEx
is for hooking into windows messages, not APIs (for example if you want to know when a window changes size or gets created).
Hooking API calls is more complicated, more messy. There is no built-in way to do it; you usually want to find a library to help you such as Detours.
Upvotes: 3