I have an application loading a library containing a callback function for a global GetMessage hook. I get the procedure and pass it to SetWindowsHookEx to be set for all running threads.
The problem is that I want the DLL function to, under a certain circumstance like a keypress, tell the original application to exit, not all applications. The only way I can think of is to create a window in the application and have the DLL call SendMessage(HWND_BROADCAST) to send a custom message that the application recognizes to exit. But I want to verify if this is the best method to do this?
Another problem arises as well. Let's say I want the DLL to perform some one-time initialization such as opening a file. If I do this in DllMain then it seems to do this multiple times because it's being loaded multiple times. Is this a fix for this? Thanks.