我正在尝试将委托传递给外部托管API 委托功能是:
type HookProc = delegate of int * nativeint * nativeint -> nativeint
代表的功能:
let HookCallback(nCode:int,wParam:System.IntPtr,lParam:System.IntPtr) =
let t = (int)wParam
if t = WM_KEYUP then
let vkCode:int = Marshal.ReadInt32(lParam)
printfn "%A The Pressed key code is : " vkCode
CallNextHookEx(_hookID, nCode, wParam, lParam)
我在创建委托时遇到的问题
let HookProcF = new HookProc(HookCallback)
得到此错误
Error 1 Type mismatch. Expecting a int -> nativeint -> nativeint -> nativeint
but given a int * System.IntPtr * nativeint -> System.IntPtr
The type 'int' does not match the type 'int * System.IntPtr * nativeint'
我问过相关的问题 here
答案 0 :(得分:3)
答案在错误消息中 - 当它显示int <> int->nativeint ...
时。
你需要使用咖喱表格来实现这样的功能
let HookCallback (nCode:int) (wParam:System.IntPtr) (lParam:System.IntPtr) =