Sending APDU with winscard.dll (PC/SC) without a smart card connected

徘徊边缘 提交于 2019-12-02 09:25:12

I'm not sure why is configuring a reader is made by sending APDUs to a card. It should not be that way. SCardTransmit is for sending command to a card, and it will not work if there is no card (unless you hack the driver so it lies that there is actually a card inserted).

You might be looking for one of these APIs: https://msdn.microsoft.com/en-us/library/windows/desktop/aa375369(v=vs.85).aspx It gives more direct acces to your reader / card.

Specifying that what configurations you wish to set on the reader might increase the change to get an answer that helps you.

Steffi Castro

Simple way is to only switch on/off Smart card reader is to call SCardEstablishContext for connecting to reader. Note : This will not connect to Smartcard:

    /// <summary>
    /// Native SCardEstablishContext function from winscard.dll
    /// </summary>
    /// <param name="dwScope"></param>
    /// <param name="pvReserved1"></param>
    /// <param name="pvReserved2"></param>
    /// <param name="phContext"></param>
    /// <returns></returns>
    [DllImport("winscard.dll", SetLastError=true)]
    internal    static  extern  int SCardEstablishContext(UInt32 dwScope,
        IntPtr pvReserved1,
        IntPtr pvReserved2,
        IntPtr phContext);

To release Reader: this will power off /Release reader handle from the current process. Note : does not have any relation to the smart card.

    /// <summary>
    /// Native SCardReleaseContext function from winscard.dll
    /// </summary>
    /// <param name="hContext"></param>
    /// <returns></returns>
    [DllImport("winscard.dll", SetLastError=true)]
    internal static extern  int SCardReleaseContext(UInt32 hContext);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!