I’m trying to get messages from the process that loaded my DLL.
I’ve tried:
SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)WndProc, hInstance, 0);
Which gives me error popups about how “Program X could not be started because Y.dll is missing from your system”. This is the reason I put “safely” in the title.
I’ve also tried:
SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)WndProc, hInstance, threadId);
Where threadId is the result of GetCurrentThreadId() in my DLLMain.
This one works, but I don’t get any messages for the window (just a bunch of 512 and 1025).
Messages are related to threads and windows, your DLL might be loaded by processes. So there is no direct correspondence.
Hooks on the other hand are either global or per-thread.
All together this means that you have to choose whether you want messages just from specific threads, or global (all threads in all processes in specific desktop) where you will filter out the process of your interest yourself.
Your second code snippet is a thread hook. The first one is the global hook where you definitely do something wrong as successful hook itself does not cause error messages you mentioned.