ISCard::AttachByReader 方法

[ AttachByReader 方法可用于“要求”部分中指定的操作系统。 它不适用于 Windows Server 2003 Service Pack 1 (SP1) 及更高版本、Windows Vista、Windows Server 2008 和操作系统的后续版本。 智能卡模块提供类似的功能。]

AttachByReader 方法在命名读取器中打开智能卡

语法

HRESULT AttachByReader(
  [in] BSTR              bstrReaderName,
  [in] SCARD_SHARE_MODES ShareMode,
  [in] SCARD_PROTOCOLS   PrefProtocol
);

parameters

bstrReaderName [in]

包含智能卡读取器的名称的 BSTR

ShareMode [in]

声明对智能卡的访问权限的模式。

含义
独家
没有其他人使用此连接到智能卡。
共享
其他应用程序可以使用此连接。

 

PrefProtocol [in]

首选协议值。

T0

T1

RAW

T0|T1

返回值

方法返回以下可能值之一。

返回代码 说明
S_OK
在命名读取器中打开智能卡已成功完成。
E_INVALIDARG
传入函数的一个或多个参数有问题。

 

备注

除了上面列出的 COM 错误代码外,如果调用智能卡函数来完成请求,则此接口可能返回智能卡错误代码。 有关详细信息,请参阅 智能卡返回值

使用完读取器后,通过调用 ISCard::D etach 方法释放附件。

示例

以下示例演示如何附加到指定的智能卡读取器中的智能卡。

#include <windows.h>
#include <stdio.h>
#include <Scardmgr.h>

// The reader name is vendor specific; change as needed.
#define READER_NAME L"Vendor Reader 0"

void main()
{
    BSTR     bstrReader = NULL;
    HRESULT  hr;

    bstrReader = SysAllocString(READER_NAME);
    if (NULL == bstrReader)
    {
        // Error encountered.
        exit(1);
    }

    // Connect to the reader.
    hr = pISCard->AttachByReader(bstrReader, SHARED, T0);
    if (FAILED(hr))
    {
        printf("Failed AttachByReader\n");
        // Take other error handling action.
        // ...
    }

    // Detach reader by calling ISCard::Detach (not shown).
    // ...

    // When done, free BSTR.
    if (NULL != bstrReader)
        SysFreeString(bstrReader);
}

要求

要求
最低受支持的客户端
Windows XP [仅限桌面应用]
最低受支持的服务器
Windows Server 2003 [仅限桌面应用]
客户端支持终止
Windows XP
终止服务器支持
Windows Server 2003
标头
Scardmgr.h
类型库
Scardmgr.tlb
DLL
Scardssp.dll
IID
IID_ISCard定义为 1461AAC3-6810-11D0-918F-00AA00C18068

另请参阅

AttachByHandle

分离

ISCard

附加