调用SetWindowsHookEx函数里面VS2008调试器总是返回NULL [英] Calling SetWindowsHookEx inside VS2008 debugger always returns NULL

查看:242
本文介绍了调用SetWindowsHookEx函数里面VS2008调试器总是返回NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在努力.Net应用程序,做一个低级别的键盘钩子。当我们调用SetWindowsHookEx函数内部调试器运行的呼叫总是失败。

从编译的可执行文件运行一切时工作正常。如果我们重视PROCESSS中的SetWindowsHookEx函数被调用一切正常了。

我读某处(我不记得),该VS已经做了低级别的键盘钩子,但是这不应该是一个问题,还有就是CallNextHook功能。

有人知道发生了什么事?

编辑:在code是pretty的straigfoward,引发异常的内部调试器,但没有外面

 的Public Sub New()
    m_callback =新NativeMethods.KeyboardHookDelegate(AddressOf KeyboardCallback)
结束小组

公共Sub启动()
    m_handle = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_KEYBOARD_LL,m_callback,Marshal.GetHINSTANCE(Reflection.Assembly.GetExecutingAssembly()。GetModules()(0))。ToInt32,0)
    如果m_handle = 0则
        抛出新的异常()
    结束如果
结束小组
 

解决方案

一个猜测可能是VS运行可能会出现不同的反射.vshost.exe的过程,但我不能肯定地说。我们使用'Process.GetCurrentProcess()。MainModule`得到模块传递。也许给一个尝试。

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

解决方案

A guess might be that VS is running the .vshost.exe process that might appear differently in reflection, but I can't say for sure. We use 'Process.GetCurrentProcess().MainModule` to get the module to pass in. Maybe give that a try.

这篇关于调用SetWindowsHookEx函数里面VS2008调试器总是返回NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆