I have a program that sets a hook on another window. I want this program to know if my hook function received a message. How can I do it?
I’ve had an idea to send message from hook function to my main window, but I don’t know how to pass the HWND handler. Also I don’t want to use EnumWindows or FindWindow to find my main window.
>Solution :
The simplest solution is to store your target HWND in shared memory that both the main program and the hook can access.
If your compiler supports #pragma data_seg() (ie, MSVC), you can use that to declare an HWND variable in a shared code section in a DLL. Have your main program and your hook use the same DLL. See Process shared variable #pragma data_seg usage.
Otherwise, you can use CreateFileMapping()+MapViewOfFile() to allocate a block of memory at runtime, and then store/read the HWND value from it. See Creating Named Shared Memory.
Either way, the main program can then assign the shared hwnd, and the hook can read it.