Calling SetWindowsHookEx inside VS2008 debugger always returns NULL
- by SoMoS
we're working on a .Net application that does a low level keyboard hook. When we call the SetWindowsHookEx running inside the debugger the call always fail.
When running from the compiled executable everything works fine. If we attach to the processs the the SetWindowsHookEx has been called everything works too.
I've read somewhere (I can not remember) that VS already does a low level keyboard hook but this shouldn't be a problem as there is the CallNextHook function.
Someone knows what's happening?
EDIT: The code is pretty straigfoward, the exception is thrown inside debugger but not outside.
Public Sub New()
m_callback = New NativeMethods.KeyboardHookDelegate(AddressOf KeyboardCallback)
End Sub
Public Sub Start()
m_handle = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_KEYBOARD_LL, m_callback, Marshal.GetHINSTANCE(Reflection.Assembly.GetExecutingAssembly().GetModules()(0)).ToInt32, 0)
If m_handle = 0 Then
Throw New Exception()
End If
End Sub