无法将 SmartCard 与 winscard.dll 连接?
Posted
技术标签:
【中文标题】无法将 SmartCard 与 winscard.dll 连接?【英文标题】:Cant Connect SmartCard with winscard.dll? 【发布时间】:2018-08-31 18:24:40 【问题描述】:我需要读取文件身份的智能卡。
我在 ASP.NET 中使用带有执行方法的 winscard.dll:
SCardConnect()
此函数返回以下错误:
retCode = -2146434970
不支持此代码。
查看最后支持的错误列表。
方法ConnectCard和发送前的参数值:
hContext = -855572480
readername = "ACS ACR1281 1S Dual Reader ICC 0"
Card.SCARD_SHARE_SHARED = 2
Card.SCARD_PROTOCOL_T0 = 1
Card.SCARD_PROTOCOL_T1 = 2
hCard = 0
Protocol = 0
public bool connectCard()
connActive = true;
retCode = Card.SCardConnect(hContext, readername, Card.SCARD_SHARE_SHARED,
Card.SCARD_PROTOCOL_T0 | Card.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);
if (retCode != Card.SCARD_S_SUCCESS)
MessageBox.Show(Card.GetScardErrMsg(retCode), "Card not available", MessageBoxButtons.OK, MessageBoxIcon.Error);
connActive = false;
return false;
return true;
错误代码:
/*===========================================================
' Error Codes
'===========================================================*/
public const int SCARD_F_INTERNAL_ERROR = -2146435071;
public const int SCARD_E_CANCELLED = -2146435070;
public const int SCARD_E_INVALID_HANDLE = -2146435069;
public const int SCARD_E_INVALID_PARAMETER = -2146435068;
public const int SCARD_E_INVALID_TARGET = -2146435067;
public const int SCARD_E_NO_MEMORY = -2146435066;
public const int SCARD_F_WAITED_TOO_LONG = -2146435065;
public const int SCARD_E_INSUFFICIENT_BUFFER = -2146435064;
public const int SCARD_E_UNKNOWN_READER = -2146435063;
public const int SCARD_E_TIMEOUT = -2146435062;
public const int SCARD_E_SHARING_VIOLATION = -2146435061;
public const int SCARD_E_NO_SMARTCARD = -2146435060;
public const int SCARD_E_UNKNOWN_CARD = -2146435059;
public const int SCARD_E_CANT_DISPOSE = -2146435058;
public const int SCARD_E_PROTO_MISMATCH = -2146435057;
public const int SCARD_E_NOT_READY = -2146435056;
public const int SCARD_E_INVALID_VALUE = -2146435055;
public const int SCARD_E_SYSTEM_CANCELLED = -2146435054;
public const int SCARD_F_COMM_ERROR = -2146435053;
public const int SCARD_F_UNKNOWN_ERROR = -2146435052;
public const int SCARD_E_INVALID_ATR = -2146435051;
public const int SCARD_E_NOT_TRANSACTED = -2146435050;
public const int SCARD_E_READER_UNAVAILABLE = -2146435049;
public const int SCARD_P_SHUTDOWN = -2146435048;
public const int SCARD_E_PCI_TOO_SMALL = -2146435047;
public const int SCARD_E_READER_UNSUPPORTED = -2146435046;
public const int SCARD_E_DUPLICATE_READER = -2146435045;
public const int SCARD_E_CARD_UNSUPPORTED = -2146435044;
public const int SCARD_E_NO_SERVICE = -2146435043;
public const int SCARD_E_SERVICE_STOPPED = -2146435042;
public const int SCARD_W_UNSUPPORTED_CARD = -2146435041;
public const int SCARD_W_UNRESPONSIVE_CARD = -2146435040;
public const int SCARD_W_UNPOWERED_CARD = -2146435039;
public const int SCARD_W_RESET_CARD = -2146435038;
public const int SCARD_W_REMOVED_CARD = -2146435037;
【问题讨论】:
您建议使用哪种语言标签?我查看了常见问题解答 (meta.stackexchange.com/questions/184108/…),找不到任何适用于 ASP.NET 的内容。 【参考方案1】:我建议将错误代码整数(C# 偶然?)转换为无符号数。它们的使用范围更广,可搜索性也更好。
PCSC-lite 文档声明代码0x80100066
表示卡无响应。这似乎适合您的问题,因此想法是,先尝试另一张卡,然后换读卡器。
更新:后来我注意到,您的错误代码列表对于某些代码似乎有所不同,因为它为 unreponsive card 列出了不同的编号,分析差异也可能会有所帮助。
【讨论】:
以上是关于无法将 SmartCard 与 winscard.dll 连接?的主要内容,如果未能解决你的问题,请参考以下文章
来自 O2Micro 阅读器上的 WINSCARD.DLL 方法 SCardTransmit 的未知响应以及响应长度信息
在哪里可以找到用于 VC++ 2010(Win 7)中 PC/SC 编程的 winscard.lib?
Microsoft Usbccid Smartcard Reader(WUDF)