ISCard::AttachByReader method
[The AttachByReader method is available for use in the operating systems specified in the Requirements section. It is not available for use in Windows Server 2003 with Service Pack 1 (SP1) and later, Windows Vista, Windows Server 2008, and subsequent versions of the operating system. The Smart Card Modules provide similar functionality.]
The AttachByReader method opens the smart card in the named reader.
Syntax
HRESULT AttachByReader(
[in] BSTR bstrReaderName,
[in] SCARD_SHARE_MODES ShareMode,
[in] SCARD_PROTOCOLS PrefProtocol
);
Parameters
-
bstrReaderName [in]
-
A BSTR that contains the name of the smart card reader.
-
ShareMode [in]
-
Mode in which to claim access to the smart card.
Value Meaning - EXCLUSIVE
No one else use this connection to the smart card. - SHARED
Other applications can use this connection. -
PrefProtocol [in]
-
Preferred protocol value.
-
T0
-
T1
-
RAW
-
T0|T1
-
Return value
The method returns one of the following possible values.
Return code | Description |
---|---|
|
Open on the smart card in the named reader has been completed successfully. |
|
There is something wrong with one or more of the parameters passed into the function. |
Remarks
In addition to the COM error codes listed above, this interface may return a smart card error code if a smart card function was called to complete the request. For more information, see Smart Card Return Values.
When you have finished using the reader, release the attachment by calling the ISCard::Detach method.
Examples
The following example shows attaching to a smart card in a specified smart card reader.
#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);
}
Requirements
Requirement | Value |
---|---|
Minimum supported client |
Windows XP [desktop apps only] |
Minimum supported server |
Windows Server 2003 [desktop apps only] |
End of client support |
Windows XP |
End of server support |
Windows Server 2003 |
Header |
|
Type library |
|
DLL |
|
IID |
IID_ISCard is defined as 1461AAC3-6810-11D0-918F-00AA00C18068 |
See also