Private Sub SetEvents()
WR_mfSetEvent E_EVENT_CODELINE, AddressOf MFS100_OnCodeline
WR_mfSetEvent E_EVENT_DOCUMENTDONE, AddressOf MFS100_OnDocumentDone
WR_mfSetEvent E_EVENT_ERROR, AddressOf MFS100_OnError
WR_mfSetEvent E_EVENT_ALLDONE, AddressOf MFS100_OnAllDone
End Sub
Enum EventEnum
E_EVENT_CODELINE = 0
E_EVENT_RAWIMAGEFRONT
E_EVENT_RAWIMAGEBACK
E_EVENT_RAWMICRBUFFER
E_EVENT_RAWOCRBUFFER
E_EVENT_DOCUMENTDONE
E_EVENT_WARNING
E_EVENT_ERROR
E_EVENT_ALLDONE
End Enum
如何将此代码转换为C#?
更新1:我遇到了Scan和ScanFeeder的问题。 ScanFeeder返回MICR代码,但我无法处理它。扫描功能会出现读写内存错误。
' mflib routines
' ------------------------------------------------------------------------------------
Declare Function mfInit Lib "mflib.dll.stdcall" (ByVal mode As Long, ByVal fileIni As String) As Long
Declare Function mfClose Lib "mflib.dll.stdcall" (ByVal mode As Long) As Long
Declare Function mfTrace Lib "mflib.dll.stdcall" (ByVal level As Long, ByVal msg As String) As Long
Declare Function mfTraceSet Lib "mflib.dll.stdcall" (ByVal mode As Long, ByVal tracelevel As Long, ByVal maxlen As Long, ByVal fullpathname As String) As Long
Declare Function mfSetParam Lib "mflib.dll.stdcall" (ByVal paramCode As Long, ByVal paramValue As String) As Long
Declare Function mfReset Lib "mflib.dll.stdcall" (ByVal mode As Long) As Long
Declare Function mfGetStatus Lib "mflib.dll.stdcall" (ByVal mode As Long, ByVal ret_statusbuffer As String) As Long
Declare Function mfScan Lib "mflib.dll.stdcall" (ByVal mode As Long, ByVal font As Long, ByVal timeout As Long, ByVal ret_codeline As String, ByRef ret_maxchars As Long) As Long
Declare Function mfEject Lib "mflib.dll.stdcall" (ByVal mode As Long, ByVal pocket As Long, ByVal timeout As Long) As Long
Declare Function mfCalib Lib "mflib.dll.stdcall" (ByVal calibID As Long, ByVal mode As Long, ByRef ret_value As Long) As Long
Declare Function mfScanFeeder Lib "mflib.dll.stdcall" (ByVal mode As Long, ByVal font As Long, ByVal timeout As Long) As Long
Declare Function mfSetEvent Lib "mflib.dll.stdcall" (ByVal eventId As Long, ByVal callback As Long) As Long
Declare Function mfGetErrorDescription Lib "mflib.dll.stdcall" (ByVal errorCode As Long, ByVal ret_errorDescription As String) As Long
Declare Function mfIQALoadConfig Lib "mflib.dll.stdcall" (ByVal configfile As String) As Long
Declare Function mfIQASetParameter Lib "mflib.dll.stdcall" (ByVal paramid As Long, ByVal value As String) As Long
Declare Function mfIQATestFile Lib "mflib.dll.stdcall" (ByVal mask As Long, ByVal front As String, ByVal rear As String) As Long
Declare Function mfIQAGetErrorDescription Lib "mflib.dll.stdcall" (ByVal errorid As Long, ByVal desc As String, ByVal maxlen As Long) As Long
Declare Sub mfSort Lib "mflib.dll.stdcall" (ByVal pocket As Long)
Declare Function mfStop Lib "mflib.dll.stdcall" () As Long
更新2:
Public Function WR_mfSetEvent(eventId As Long, callback As Long) As Long
WriteEvent " event " & GetEventName(eventId)
WR_mfSetEvent = mfSetEvent(eventId, callback)
WriteEventMFSRes WR_mfSetEvent
CScannerForm.lsTest.AddItem ("mfSetEvent : " & WR_mfSetEvent)
End Function
Public Sub WriteEventMFSRes(res As Long)
If res >= 0 Then
If res <> 1 Then WriteEventRes " (" & res & ")"
Else
WriteEventRes " (" & res & "='" & WR_mfGetErrorDescription(res) & "')"
End If
End Sub
更新2:这是正确的方法。我以这种方式得到回调
MFS100_CodeLineDelegate OnCodeline = new MFS100_CodeLineDelegate(MFS100_OnCodeLine);
Adress = Marshal.GetFunctionPointerForDelegate(OnCodeline);
mfSetEvent(0, Adress.ToInt32());
答案 0 :(得分:3)
转换枚举很容易; C#使用了非常相似的语法(抛出几个花括号):
enum EventEnum
{
E_EVENT_CODELINE = 0,
E_EVENT_RAWIMAGEFRONT,
E_EVENT_RAWIMAGEBACK,
E_EVENT_RAWMICRBUFFER,
E_EVENT_RAWOCRBUFFER,
E_EVENT_DOCUMENTDONE,
E_EVENT_WARNING,
E_EVENT_ERROR,
E_EVENT_ALLDONE
}
SetEvents
sub将成为返回类型为void
的函数,所有方法调用必须包含在括号中(在VB.NET中也是如此),并且您不需要{ {1}}运营商:
AddressOf
您可能必须将这些功能(例如private void SetEvents()
{
WR_mfSetEvent(E_EVENT_CODELINE, MFS100_OnCodeline);
WR_mfSetEvent(E_EVENT_DOCUMENTDONE, MFS100_OnDocumentDone);
WR_mfSetEvent(E_EVENT_ERROR, MFS100_OnError);
WR_mfSetEvent(E_EVENT_ALLDONE, MFS100_OnAllDone);
}
)实现为delegates。 C#有一个完全不同的语法模型,用于为委托/事件分配函数,但是你没有提出VB 6中内置的典型事件。这是某种自定义库,所以如果不确切知道它们是什么,很难更具体。定义和他们做了什么。
答案 1 :(得分:0)
看看pInvoke。这将让您了解如何访问DLL中定义的内容。
我搜索了WR_mfSetEvent
但却一无所获 - 这是一个你正在使用的私人图书馆吗?如果不知道你正在做什么,就很难帮助你。