如果读卡器中没有卡,我在获取 PCSC 读卡器序列号时遇到问题。我正在使用 winscard.dll 和 c++。
以下代码仅适用于读卡器中存在卡的情况。否则不检索 SCardHandle。我还没有找到任何其他方法来获取 SCardHandle。
SCARDHANDLE hCardHandle;
SCARDCONTEXT hSC;
WCHAR pCardReaderName[256];
LONG lReturn;
lReturn = SCardEstablishContext(SCARD_SCOPE_USER, 0, 0, &hSC);
if (lReturn != SCARD_S_SUCCESS)
{
Console::WriteLine("SCardEstablishContext() failed\n");
return;
}
my_select_reader(hSC, pCardReaderName); // just shows reader names in console and requires you to pick one
// connect to smart card
DWORD dwAP;
lReturn = SCardConnect( hSC,
(LPCWSTR)pCardReaderName,
SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1 | SCARD_PROTOCOL_RAW,
&hCardHandle,
&dwAP );
if ( SCARD_S_SUCCESS != lReturn )
{
Console::WriteLine("Failed SCardConnect\n");
exit(1); // Or other appropriate action.
}
// get reader serial no
LPBYTE pbAtr = NULL;
DWORD cByte = SCARD_AUTOALLOCATE;
lReturn = SCardGetAttrib(hCardHandle,
SCARD_ATTR_VENDOR_IFD_SERIAL_NO,
(LPBYTE)&pbAtr,
&cByte);
if ( SCARD_S_SUCCESS != lReturn )
{
Console::WriteLine("Failed to retrieve Reader Serial\n");
exit(1); // Or other appropriate action.
}
printf("serial no: %s", pbAtr);
SCardFreeMemory(hCardHandle, pbAtr);
有没有办法在不连接卡的情况下获取读卡器序列号?