获取智能卡序列号SCardGetAttrib会返回错误#50

时间:2013-07-16 09:35:22

标签: c# smartcard winscard

我正在尝试使用SCardGetAttrib中的Winscard.dll功能阅读智能卡序列号 但它总是返回错误#50,我找了它可能意味着什么,并发现它可能是读卡器的驱动程序!

这是答案的链接:http://marc.info/?l=ms-smartcardsdk&m=103430435428137&w=2

我更新了驱动程序,(顺便说一句,我使用ACS-ACR88智能卡读卡器)没有运气。

这是我到目前为止所做的:

    private static UInt32 SCardAttrValue(UInt32 attrClass, UInt32 val)
    {
        return (attrClass) * (2 << 16) | val;
    }

    private const uint SCARD_CLASS_VENDOR_DEFINED = 7;

    public static UInt32 VENDOR_NAME { get { return SCardAttrValue(SCARD_CLASS_VENDOR_DEFINED, 0x100); } }

    private void button2_Click(object sender, EventArgs e)
    {
        var lReturn = GetAttribute((uint)hCard, VENDOR_NAME);
        lblData.Text = lReturn.ToString();

    }

    public byte[] GetAttribute(uint m_hCard, UInt32 AttribId)
    {
        byte[] attr = new byte[] { };// null;
        UInt32 attrLen = 0;
        attr.Initialize();
        int m_nLastError = ModWinsCard.SCardGetAttrib(m_hCard, AttribId, attr, out attrLen); //====> error 50 occurs here
        if (m_nLastError == 0)
        {
            if (attrLen != 0)
            {
                attr = new byte[attrLen];
                m_nLastError = ModWinsCard.SCardGetAttrib(m_hCard, AttribId, attr, out attrLen);
                if (m_nLastError != 0)
                {
                    string msg = "SCardGetAttr error: " + m_nLastError;
                    throw new Exception(msg);
                }
            }
        }
        else
        {
            string msg = "SCardGetAttr error: " + m_nLastError;
            throw new Exception(msg);
        }     }

1 个答案:

答案 0 :(得分:1)

也许为时已晚,但我认为您的AttribId价值是错误的。您可以在下面的链接中查找AttribId值,而不是自己从hexa转换为十进制

http://pyscard.sourceforge.net/epydoc/smartcard.scard.scard-module.html