共用方式為


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
);

參數

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

附加