我在(stdcall)DLL 中有一些函数,它们采用函数指针来执行回调。
该方法DeviceStateChangedNotify
并CardDataStateChangedNotify
接受Long
回调地址的参数。
这是一个 VB6 示例:
Declare Sub DeviceStateChangedNotify Lib "Device.dll" (ByVal lpFunc As Long)
Declare Sub CardDataStateChangedNotify Lib "Device.dll" (ByVal lpFunc As Long)
Public Sub SetupCallBacks()
Call DeviceStateChangedNotify(AddressOf OnEventDeviceStateChanged)
Call CardDataStateChangedNotify(AddressOf OnEventCardDataStateChanged)
End Sub
Public Sub OnEventDeviceStateChanged(ByVal parm As Long)
...
End Sub
Public Sub OnEventCardDataStateChanged(ByVal parm As Long)
...
End Sub
我如何在 C# 中做到这一点?
我试图创建一个具有相同方法签名的委托,OnEventDeviceStateChanged
但OnEventCardDataStateChanged
似乎不起作用:
delegate void DeviceStateChanged(long parm);
DeviceStateChanged stateChanged = EventDeviceStateChanged;
CardDataStateChangedNotify(stateChanged);
这会在最后一行产生语法错误:
无法从“DeviceStateChanged”转换为“long”