SetWindowsHookEx和VB.NET 2005 [英] SetWindowsHookEx and VB.NET 2005
问题描述
我需要一些帮助,如何在vb.net 2005中编写SetWindowsHookEx来挂钩kb输入。
这是声明:
hHOOKKb = SetWindowsHookEx(_
WH_KEYBOARD,_
lpfn,_
hMod,_
dwThreadId)
这是来自MSDN Library:
lpfn [in]指向钩子程序的指针。
" hMod [in]处理包含钩子程序指向的DLL通过lpfn参数获得
。"
" dwThreadId [in]指定
hook
程序是关联的。
从我的程序之外或从任何桌面获取来自另一个线程的kb事件
线程我应该将钩子程序放在DLL(一个单独的module.vb)中吗?并且
如果是这样我如何得到它的句柄和lpfn?
谢谢。
-
bruno
从我的程序之外的任何线程或任何桌面获取kb事件
我应该将钩子程序放在DLL(一个单独的module.vb)中吗?如果是这样的话我怎么得到它的句柄和lpfn?
你不能用VB.NET或任何其他生成<的语言编写全局钩子br />
托管代码。更好地使用普通老C。
Mattias
-
Mattias Sj?gren [C#MVP] mattias @ mvps .org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
请回复到新闻组。
Bruno,
我刚刚在我的博客上发布了一个例子:
http://www.colinneller.com/博客/彼尔姆... e5918a39c.aspx 。
看一看,看看它是不是你要找的东西。
-
Colin Neller
http:// www.colinneller.com/blog
" bruno" <峰; br *** @ community.nospam>在消息中写道
新闻:是********************************** @ microsof t.com ...我需要一些帮助,如何在vb.net 2005中编写SetWindowsHookEx来挂钩kb
输入。
这是声明:
hHOOKKb = SetWindowsHookEx(_
WH_KEYBOARD,_
lpfn,_
hMod,_
dwThreadId)
这是来自MSDN Library:
lpfn [in]指向钩子过程的指针。
" hMod [in]处理包含由lpfn参数指向
的钩子过程的DLL。
dwThreadId [in ]指定与
hook
过程相关联的线程的标识符。
从我的程序外部或任何<从另一个线程获取kb事件桌面
线程我应该把钩程序放在DLL中(一个sep arate module.vb)?
如果是这样的话我如何获得它的句柄和lpfn?
谢谢。
-
bruno
Colin,
谢谢您的样品。这就是我想要的。
我刚试过它:
Hks.InstallHooks( )
但是我收到了一个错误:SetWindowsHookEx失败了。
在我的试验中,写道:
hHOOK = SetWindowsHookEx(WH_KEYBOARD,_
hookproc,_
IntPtr.Zero,_
AppDomain.GetCurrentThreadId())
我能够连接正在运行的程序。但我无法挂钩所有
线程。
你能解释一下我的更多信息:
Marshal.GetHINSTANCE(Reflection.Assembly.GetExecut ingAssembly()。GetModules()(0)),0)
是什么意思?
-
bruno
" Colin Neller"写道:
Bruno,
我刚刚在我的博客上发布了一个例子:
http://www.colinneller.com/blog/Perm...e5918a39c.aspx 。
看一看,看看它是不是你想要的。
-
科林·奈勒
http://www.colinneller.com/blog
"布鲁诺" <峰; br *** @ community.nospam>在消息中写道
新闻:是********************************** @ microsof t.com。 ..我需要一些帮助,如何在vb.net 2005中编写SetWindowsHookEx来挂钩kb
输入。
这是声明:
hHOOKKb = SetWindowsHookEx(_
WH_KEYBOARD,_
lpfn,_
hMod,_
dwThreadId)
这是来自MSDN Library:
lpfn [in]指向钩子过程的指针。
" hMod [in]处理包含由lpfn参数指向的钩子过程的DLL。
dwThreadId [in]指定标识符与
hook
过程相关联的线程。
从我的程序之外或从任何桌面获取来自另一个线程的kb事件
线程我应该将钩子程序放在DLL中(单独的module.vb)?
如果是这样的话我如何获得它的句柄和lpfn?
谢谢。
-
bruno
I need some help on how write SetWindowsHookEx in vb.net 2005 to hook kb input.
this is the statement:
hHOOKKb = SetWindowsHookEx( _
WH_KEYBOARD, _
lpfn, _
hMod, _
dwThreadId)
And this is from MSDN Library:
lpfn [in] Pointer to the hook procedure.
"hMod [in] Handle to the DLL containing the hook procedure pointed to
by the lpfn parameter."
"dwThreadId [in] Specifies the identifier of the thread with which the
hook
procedure is to be associated."
To get kb events from another thread, outside my program or from any desktop
thread should I put the hook procedure in a DLL (a separate module.vb)? And
if so how do I get its Handle and lpfn?
Thanks.
--
bruno
To get kb events from another thread, outside my program or from any desktop
thread should I put the hook procedure in a DLL (a separate module.vb)? And
if so how do I get its Handle and lpfn?
You can''t write global hooks in VB.NET or any other language producing
managed code. Better use plain old C for that.
Mattias
--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Bruno,
I just posted an example on my blog:
http://www.colinneller.com/blog/Perm...e5918a39c.aspx.
Take a look and see if it''s what you''re looking for.
--
Colin Neller
http://www.colinneller.com/blog
"bruno" <br***@community.nospam> wrote in message
news:BE**********************************@microsof t.com...I need some help on how write SetWindowsHookEx in vb.net 2005 to hook kb
input.
this is the statement:
hHOOKKb = SetWindowsHookEx( _
WH_KEYBOARD, _
lpfn, _
hMod, _
dwThreadId)
And this is from MSDN Library:
lpfn [in] Pointer to the hook procedure.
"hMod [in] Handle to the DLL containing the hook procedure pointed to
by the lpfn parameter."
"dwThreadId [in] Specifies the identifier of the thread with which the
hook
procedure is to be associated."
To get kb events from another thread, outside my program or from any
desktop
thread should I put the hook procedure in a DLL (a separate module.vb)?
And
if so how do I get its Handle and lpfn?
Thanks.
--
bruno
Colin,
thank you for the sample. It is what I was looking for.
I just tried it:
Dim Hks As New GlobalHook
Hks.InstallHooks()
but I got an error: "SetWindowsHookEx failed."
In my trials, writing:
hHOOK = SetWindowsHookEx(WH_KEYBOARD, _
hookproc, _
IntPtr.Zero, _
AppDomain.GetCurrentThreadId())
I was able to hook my running program. But I was not able to hook all
threads.
Can you explain me more about :
Marshal.GetHINSTANCE(Reflection.Assembly.GetExecut ingAssembly().GetModules()(0)), 0)
what does it mean?
--
bruno
"Colin Neller" wrote:
Bruno,
I just posted an example on my blog:
http://www.colinneller.com/blog/Perm...e5918a39c.aspx.
Take a look and see if it''s what you''re looking for.
--
Colin Neller
http://www.colinneller.com/blog
"bruno" <br***@community.nospam> wrote in message
news:BE**********************************@microsof t.com...I need some help on how write SetWindowsHookEx in vb.net 2005 to hook kb
input.
this is the statement:
hHOOKKb = SetWindowsHookEx( _
WH_KEYBOARD, _
lpfn, _
hMod, _
dwThreadId)
And this is from MSDN Library:
lpfn [in] Pointer to the hook procedure.
"hMod [in] Handle to the DLL containing the hook procedure pointed to
by the lpfn parameter."
"dwThreadId [in] Specifies the identifier of the thread with which the
hook
procedure is to be associated."
To get kb events from another thread, outside my program or from any
desktop
thread should I put the hook procedure in a DLL (a separate module.vb)?
And
if so how do I get its Handle and lpfn?
Thanks.
--
bruno
这篇关于SetWindowsHookEx和VB.NET 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!