Calling SetWindowsHookEx inside VS2008 debugger always returns NULL

Posted by SoMoS on Stack Overflow See other posts from Stack Overflow or by SoMoS
Published on 2010-02-19T10:40:05Z Indexed on 2010/04/20 0:03 UTC
Read the original article Hit count: 399

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

© Stack Overflow or respective owner

Related posts about setwindowshookex

Related posts about .NET