WH_KEYBOARD global hook

Status
Not open for further replies.

gekoscan

New member
Joined
Jan 19, 2004
Messages
1
Hello,

http://msdn.microsoft.com/msdnmag/issues/02/10/cuttingedge/

I dont know if any of you are familiar with Dino Esposito article in MSDN magazine on .NET Hooks but I used the class he created named LocalWindowsHook that imports the below API calls

protected static extern IntPtr SetWindowsHookEx(HookType code,
HookProc func,
IntPtr hInstance,
int threadID);

and a few other necessary functions from user32.dll to implement a hook.

I ended up changing his Install function from

public void Install()
{
m_hhook = SetWindowsHookEx(
m_hookType, m_filterFunc,
IntPtr.Zero,
(int)AppDomain.GetCurrentThreadId());
}

to

public void Install()
{
m_hhook = SetWindowsHookEx(
m_hookType,
m_filterFunc,
GetHInstance(),
0);
}

public static IntPtr GetHInstance()
{
return Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]);
}

In an attempt to create a global hook using WH_KEYBOARD.

The problem I have is it doesnt work. It works globally with WH_KEYBOARD_LL but as soon as I use WH_KEYBOARD it doesnt work at all. This meaning it doesnt capture keyboard strokes in either the windows form or anywhere else. Now Dinos code worked fine for a local hook (aka the form) but I want a global or system hook.

Now I have the class he wrote in an external DLL but there must be something else i am missing. If anyone has any suggestions they would be very much appreciated.

Thanks very much.

Dino Esposito modified project and my test windows form can be found here

http://scaninc.ca/hook/globalhook.zip
 
Global hooks need to be implemented with standard c dlls, and lightweight ones at that. .NET is not suitable.

Also, even if it were, the guidelines on this forum prohibit discussion of such things as they can clearly be used for malicious purposes.
 
Status
Not open for further replies.
Back
Top