我正在尝试在使用 Win CE 6.NET 的阅读器中读取护照信息 (MRZ)。供应商的 API 是用 C++ 编写的
//[C + +]
typedef int (* CRXCALLBACK) (BYTE *pRecvBuff, nDataLen int);
int FAR PASCAL EXPORT CRX_Open (CRXCALLBACK lpDataCallback);
这是我的 VB.NET 实现
'[VB.NET]
Public Class CRX
Public Delegate Function CRXCALLBACK (ByVal pRecvBuff As System.IntPtr, ByVal nDataLen As Integer) As Integer
<DllImport("Mrz.dll", EntryPoint:="CRX_Open", SetLastError:=True)> _
Public Shared Function CRX_Open(ByVal lpDataCallback As CRXCALLBACK) As Integer
End Function
End Class
以一种形式
Private Sub CRX_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If CRX.CRX_Open(AddressOf MrzReaderCallback) <> CRX_ERR_SUCCESS Then
MessageBox.Show("CRX_Open Failed")
End Sub
Private Function MrzReaderCallback(ByVal pRecvBuff As System.IntPtr, ByVal nDataLen As Integer) As Integer
Try
Dim str As String = Marshal.PtrToStringUni(pRecvBuff)
MsgBox(str)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End Try
Return CRX_ERR_SUCCESS
但是当我收到pRecvBuff
内容时使用Marshal.PtrToStringUni (pRecvBuff, nDataLen)
返回我不可读的字符
对我有什么建议,我做错了什么?
问候
伊万