FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
TestSmartCardListReaders.c
1
2#include <winpr/crt.h>
3#include <winpr/smartcard.h>
4
5int TestSmartCardListReaders(int argc, char* argv[])
6{
7 LONG lStatus = 0;
8 LPSTR pReader = NULL;
9 SCARDCONTEXT hSC = 0;
10 LPSTR mszReaders = NULL;
11 DWORD cchReaders = SCARD_AUTOALLOCATE;
12
13 WINPR_UNUSED(argc);
14 WINPR_UNUSED(argv);
15
16 lStatus = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &hSC);
17
18 if (lStatus != SCARD_S_SUCCESS)
19 {
20 printf("SCardEstablishContext failure: %s (0x%08" PRIX32 ")\n",
21 SCardGetErrorString(lStatus), lStatus);
22 return 0;
23 }
24
25 lStatus = SCardListReadersA(hSC, NULL, (LPSTR)&mszReaders, &cchReaders);
26
27 if (lStatus != SCARD_S_SUCCESS)
28 {
29 if (lStatus == SCARD_E_NO_READERS_AVAILABLE)
30 printf("SCARD_E_NO_READERS_AVAILABLE\n");
31 else
32 return -1;
33 }
34 else
35 {
36 pReader = mszReaders;
37
38 while (*pReader)
39 {
40 printf("Reader: %s\n", pReader);
41 pReader = pReader + strlen((CHAR*)pReader) + 1;
42 }
43
44 lStatus = SCardFreeMemory(hSC, mszReaders);
45
46 if (lStatus != SCARD_S_SUCCESS)
47 printf("Failed SCardFreeMemory\n");
48 }
49
50 SCardReleaseContext(hSC);
51
52 return 0;
53}