无法在 DLL“user32”中找到名为“SetWindowsHOOKExA”的入口点
我按照网上介绍做了一个构子试验,结果提示:无法在 DLL“user32”中找到名为“SetWindowsHOOKExA”的入口点。
请高手分析一下,为什么?如何解决?
我是用vb2008平台编写的。
代码如下:
Module Module1
Public frm1 As New Form1()
Declare Function GetCurrentThreadId Lib "kernel32" Alias "GetCurrentThreadId" () As Integer
Declare Function SetWindowsHOOKEx Lib "user32" Alias "SetWindowsHOOKExA" (ByVal idHOOK As Integer, ByVal lpfn As HOOKPROC, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
Declare Function UnHOOKWindowsHOOKEx Lib "user32" (ByVal hHOOK As Integer) As Integer
Declare Function CallNextHOOKEx Lib "user32" (ByVal hHOOK As Integer, ByVal ncode As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Delegate Function HOOKPROC(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public hnextHOOKproc As Integer
Public Const PM_KEY_SPACE = &H20
Public Enum HOOKType
WH_KEYBOARD = 2
End Enum
Public Sub UnHOOK() '解HOOK
If hnextHOOKproc <> 0 Then
UnHOOKWindowsHOOKEx(hnextHOOKproc)
hnextHOOKproc = 0
End If
End Sub
Public Function SetHOOK() '设置HOOK
If hnextHOOKproc <> 0 Then
Exit Function
End If
hnextHOOKproc = SetWindowsHOOKEx(HOOKType.WH_KEYBOARD, AddressOf MyKeyboardProc, 0, GetCurrentThreadId())
End Function
Public Function MyKeyboardProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
MyKeyboardProc = 0
If nCode < 0 Then
MyKeyboardProc = CallNextHOOKEx(hnextHOOKproc, nCode, wParam, lParam)
Exit Function
End If
If wParam = PM_KEY_SPACE Then
MyKeyboardProc = 1
'写入你自己的代码
frm1.textbox1.text = "HOOK成功!"
End If
End Function
Sub main()
Application.Run(frm1)
End Sub
End Module
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call SetHOOK()
End Sub
'vb.net中没有form_unload事件了,而是用closing
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Call UnHOOK()
End Sub
End Class
[解决办法]
楼上的有误导嫌疑
SetWindowsHookEx是有A和W区分的,楼主的错误是因为大小写问题
[解决办法]
最好用 API Viewer 插件直接选择和插入到程序中。
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Dll 的函数入口是严格区分大小写的,必须注意。