'AddressOf' expression cannot be converted to 'Long' because 'Long' is not a delegate type.解决办法

 编写钩子程序时,在代码:

hHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf HookProc, App.hInstance, 0)

处出现错误,提示'AddressOf' expression cannot be converted to 'Long' because 'Long' is not a delegate type.

 

SetWindowsHookEx的原来的定义如下:

 Private 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

于是我新定义了一个和HookProc一样的函数:

Public Delegate Function HookProcBase(ByVal nCode As Long, ByVal wParam As Long, ByVal lparam As Long) As Long

然后把SetWindowsHookEx改为:

Public Declare Function SetWindowsHookEx Lib "user32" _ Alias "SetWindowsHookExA" (ByVal idHook As Long, _ ByVal lpfn As HookProcBase, ByVal hmod As Long, ByVal _ dwThreadID As Long) As Long

这样就没有问题了。

你可能感兴趣的:('AddressOf' expression cannot be converted to 'Long' because 'Long' is not a delegate type.解决办法)