Installing A system wide CBT hook
Hi im trying to install a CBT system wide hook.
In the hook callback method i just simply write the code parameter to the debug window.
My code works fine when i specify a specific thread to monitor,
however when i try and install a system wide hook using SetWindowsHookEx
it prints to the debug window until i move the mouse out of the programs window, at which point it stops, and the callback is no longer called.
If i return the mouse to the same window, the callback still doesnt get called.
I have also tried setting a system wide low level keyboard hook using the same code, but that works fine.
here is my code to initiate the hook system wide CBT hook:
//Retrieve current threads module name
string moduleName = Process.GetCurrentProcess().MainModule.ModuleName;
hhook = SetWindowsHookEx(m_hookType, m_filterFunc, GetModuleHandle (moduleName ), (int)0);
Im using the GetModuleHandle Api to retrieve the handle for the current module running.
here is the code for the callback function
protected int CoreHookProc(int code, IntPtr wParam, IntPtr lParam)
Debug.WriteLine("code " + code + "." + DateTime.Now.Millisecond);
if (code < 0)
return CallNextHookEx(m_hhook, code, wParam, lParam);
If anyone has any idea how to work around this problem, i would be most grateful to here from you.
thanks very much:(