FreeRDP/winpr/libwinpr/smartcard/test/TestSmartCardListReaders.c

54 lines
1.0 KiB
C
Raw Normal View History

2014-04-03 04:54:46 +04:00
#include <winpr/crt.h>
#include <winpr/smartcard.h>
int TestSmartCardListReaders(int argc, char* argv[])
{
LONG lStatus;
LPSTR pReader;
SCARDCONTEXT hSC = 0;
LPSTR mszReaders = NULL;
DWORD cchReaders = SCARD_AUTOALLOCATE;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
lStatus = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &hSC);
if (lStatus != SCARD_S_SUCCESS)
{
2019-11-06 17:24:51 +03:00
printf("SCardEstablishContext failure: %s (0x%08" PRIX32 ")\n",
SCardGetErrorString(lStatus), lStatus);
2014-04-09 18:01:58 +04:00
return 0;
}
2019-11-06 17:24:51 +03:00
lStatus = SCardListReadersA(hSC, NULL, (LPSTR)&mszReaders, &cchReaders);
if (lStatus != SCARD_S_SUCCESS)
{
if (lStatus == SCARD_E_NO_READERS_AVAILABLE)
printf("SCARD_E_NO_READERS_AVAILABLE\n");
else
return -1;
}
else
{
pReader = mszReaders;
while (*pReader)
{
printf("Reader: %s\n", pReader);
2019-11-06 17:24:51 +03:00
pReader = pReader + strlen((CHAR*)pReader) + 1;
}
lStatus = SCardFreeMemory(hSC, mszReaders);
if (lStatus != SCARD_S_SUCCESS)
printf("Failed SCardFreeMemory\n");
}
SCardReleaseContext(hSC);
2014-04-03 04:54:46 +04:00
return 0;
}