Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Installing a system wide CBT hook

Status
Not open for further replies.

bitem2k

Programmer
Jan 11, 2007
1
0
0
GB
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top