I tried to inject everything into one COM library. Currently, I have connected WH_GETMESSAGE and WH_CBT, as shown below:
BOOL TouchDetector::SetMessageHook(BOOL Install)
{
if (Install)
{
return ((mHookMessage = ::SetWindowsHookEx(WH_GETMESSAGE, MessageHookProc, mDll, 0)) != NULL)
&& ((mHookWin = ::SetWindowsHookEx(WH_CBT, WinHookProc, mDll, 0)) != NULL);
}
else
{
return UnhookWindowsHookEx(mHookMessage)
&& UnhookWindowsHookEx(mHookWin);
}
};
I also added generic variables as follows:
#pragma data_seg(".shared")
TouchDetector* pTouch = nullptr;
HHOOK mHookMessage = NULL;
HHOOK mHookWin = NULL;
#pragma data_seg()
#pragma comment(linker,"/section:.shared,rws")
By joining explorer.exe, I see that interceptors work, but not global. I also tried SetWinEventHook, but the same result: only respond to the window I created or explorer.exe.
COM dll it self is x64, since explorer is x64. Could this be a problem?
What I was trying to archive was updating the configuration of my application when the foreground window changed. I know that I can just start another thread to follow it. But I don’t like it, at present the program only passively responds to user input or calls callbacks.