我写这篇文章是为了请求你帮助我。我的要求是在 c# 上下文中使用 scard32.dll 读取和写入智能卡 (sle4428)。读卡器为单片机微系统的SCR 3310
首先,我有一个运行正确的 vb.net 代码,我能够读取和写入数据。问题是当我尝试使用 c# 做同样的事情时。我的第一次尝试是在 c# 中翻译本地调用“SCardComand”但失败了。第二次尝试是从 VB.net 代码构建一个 dll 并在 ac# 上下文中使用它,但仍然失败。
如果我写这篇文章是因为我没有更多的想法。
按照我在 VB.net 中为您提供本机调用
<DllImport("SCARD32", EntryPoint:="SCardComand", SetLastError:=True, CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Ansi, ExactSpelling:=True)> _
Public Shared Function SCardComand(ByRef handle As Integer,
<MarshalAs(UnmanagedType.VBByRefStr)> ByRef cmd As String,
ByRef cmdLen As Integer,
<MarshalAs(UnmanagedType.VBByRefStr)> ByRef dataIn As String,
ByRef dataInLen As Integer,
<MarshalAs(UnmanagedType.VBByRefStr)> ByRef dataOut As String,
ByRef dataOutLen As Integer) As Integer
End Function
这里是我对 c# 的翻译。
[DllImport("SCARD32.DLL")]
static extern UInt32 SCardComand(IntPtr handle,
[MarshalAs(UnmanagedType.LPTStr)] ref String cmd,
IntPtr cmdLen,
[MarshalAs(UnmanagedType.LPTStr)] ref String dataIn,
IntPtr dataInLen,
[MarshalAs(UnmanagedType.LPTStr)] out String dataOut,
IntPtr dataOutLen);
例如,如果我在 c# 中运行此命令,请int Ret = SCardComand(0, "Card,MemVerifyPin,FFFFF", 0,"",0, "", 0);
获取 16384,这对我来说毫无意义。
请如果有人知道如何进行......