Hi all,
I have developed a BHO that installs low level keybaord hooks and CBT
hooks globally whenever IE is opened.The keys that are pressed when IE
is active are to be captured.I am trying to check whether the IE is
active first, If it is i set a boolean flag.In the key hook proc ,if
the flag is set, the keys are sent for further processing.The keyboard
hooks is working fine(when checked separately), but the CBT hooks is
not working properly. The IE page is taking a long time to load and
after it loads, its not informing me abt whether the IE is active. The
only code returns is the Window creations.Nothing else is happening.
My hook proc is as follows:
public static int CbtHookProc(int nCode, IntPtr wParam,IntPtr lParam)
{
StringBuilder title = new StringBuilder();
string classname;
title.Capacity=10;
if(nCode==HCBT_ACTIVATE)
{
try{
GetClassName(wParam,title,10);
classname=title.ToString();
if(classname.StartsWith("IE"))
IE_Active=true; //an bool variable set to false
initially
else
IE_Active=false;
}
catch(Exception e) {
MessageBox.Show(e.ToString());
}
}
return CallNextHookEx(CBTHook,nCode,wParam,lParam);
}
Win32 Import for GetClassName is as follows:
[DllImport("user32.dll")]
protected static extern int GetClassName(IntPtr hwnd,
StringBuilder lpClassName, int nMaxCount);
Is this correct?If so , y is this not working? wat am i missing in
this?.
thanks and regards,
Hema
Mattias Sjögren - 10 Apr 2006 20:17 GMT
>I have developed a BHO that installs low level keybaord hooks and CBT
>hooks globally
You can't implement global CBT hooks in managed code.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Hema - 11 Apr 2006 06:23 GMT
Hi,
So my mistake is in trying to develope a CBT hook globally? If i make
this application i.e. both keyboard hook and CBT thread specific,will
it b fine?
Thanks for your reply.
Regards,
hema
mabra - 28 May 2006 16:17 GMT
Hi !
Have a look for http://www.codeproject.com/csharp/GlobalSystemHook.asp
This contains a small [managed] C++ library which should allow global hooks.
I've not verified this and I am not an expert on this theme. So far I
understand the limitation, you should be able to create a hook for your
IE, but not globally [without the above mentioned helper dll].
Regards,
Manfred
> Hi,
> So my mistake is in trying to develope a CBT hook globally? If i make
[quoted text clipped - 4 lines]
> Regards,
> hema