36 static const WCHAR* listW[] = {
nullptr, L
"SCard$AllReaders\000", L
"SCard$DefaultReaders\000",
37 L
"SCard$LocalReaders\000", L
"SCard$SystemReaders\000" };
38 static const char* listA[] = {
nullptr,
"SCard$AllReaders\000",
"SCard$DefaultReaders\000",
39 "SCard$LocalReaders\000",
"SCard$SystemReaders\000" };
41 static std::string scope2str(DWORD scope)
45 case SCARD_SCOPE_USER:
46 return "SCARD_SCOPE_USER";
47 case SCARD_SCOPE_TERMINAL:
48 return "SCARD_SCOPE_TERMINAL";
49 case SCARD_SCOPE_SYSTEM:
50 return "SCARD_SCOPE_SYSTEM";
56 static std::string err2str(LONG code)
60 case ERROR_BROKEN_PIPE:
61 return "ERROR_BROKEN_PIPE";
62 case SCARD_E_BAD_SEEK:
63 return "SCARD_E_BAD_SEEK";
64 case SCARD_E_CANCELLED:
65 return "SCARD_E_CANCELLED";
66 case SCARD_E_CANT_DISPOSE:
67 return "SCARD_E_CANT_DISPOSE";
68 case SCARD_E_CARD_UNSUPPORTED:
69 return "SCARD_E_CARD_UNSUPPORTED";
70 case SCARD_E_CERTIFICATE_UNAVAILABLE:
71 return "SCARD_E_CERTIFICATE_UNAVAILABLE";
72 case SCARD_E_COMM_DATA_LOST:
73 return "SCARD_E_COMM_DATA_LOST";
74 case SCARD_E_DIR_NOT_FOUND:
75 return "SCARD_E_DIR_NOT_FOUND";
76 case SCARD_E_DUPLICATE_READER:
77 return "SCARD_E_DUPLICATE_READER";
78 case SCARD_E_FILE_NOT_FOUND:
79 return "SCARD_E_FILE_NOT_FOUND";
80 case SCARD_E_ICC_CREATEORDER:
81 return "SCARD_E_ICC_CREATEORDER";
82 case SCARD_E_ICC_INSTALLATION:
83 return "SCARD_E_ICC_INSTALLATION";
84 case SCARD_E_INSUFFICIENT_BUFFER:
85 return "SCARD_E_INSUFFICIENT_BUFFER";
86 case SCARD_E_INVALID_ATR:
87 return "SCARD_E_INVALID_ATR";
88 case SCARD_E_INVALID_CHV:
89 return "SCARD_E_INVALID_CHV";
90 case SCARD_E_INVALID_HANDLE:
91 return "SCARD_E_INVALID_HANDLE";
92 case SCARD_E_INVALID_PARAMETER:
93 return "SCARD_E_INVALID_PARAMETER";
94 case SCARD_E_INVALID_TARGET:
95 return "SCARD_E_INVALID_TARGET";
96 case SCARD_E_INVALID_VALUE:
97 return "SCARD_E_INVALID_VALUE";
98 case SCARD_E_NO_ACCESS:
99 return "SCARD_E_NO_ACCESS";
101 return "SCARD_E_NO_DIR";
102 case SCARD_E_NO_FILE:
103 return "SCARD_E_NO_FILE";
104 case SCARD_E_NO_KEY_CONTAINER:
105 return "SCARD_E_NO_KEY_CONTAINER";
106 case SCARD_E_NO_MEMORY:
107 return "SCARD_E_NO_MEMORY";
108 case SCARD_E_NO_PIN_CACHE:
109 return "SCARD_E_NO_PIN_CACHE";
110 case SCARD_E_NO_READERS_AVAILABLE:
111 return "SCARD_E_NO_READERS_AVAILABLE";
112 case SCARD_E_NO_SERVICE:
113 return "SCARD_E_NO_SERVICE";
114 case SCARD_E_NO_SMARTCARD:
115 return "SCARD_E_NO_SMARTCARD";
116 case SCARD_E_NO_SUCH_CERTIFICATE:
117 return "SCARD_E_NO_SUCH_CERTIFICATE";
118 case SCARD_E_NOT_READY:
119 return "SCARD_E_NOT_READY";
120 case SCARD_E_NOT_TRANSACTED:
121 return "SCARD_E_NOT_TRANSACTED";
122 case SCARD_E_PCI_TOO_SMALL:
123 return "SCARD_E_PCI_TOO_SMALL";
124 case SCARD_E_PIN_CACHE_EXPIRED:
125 return "SCARD_E_PIN_CACHE_EXPIRED";
126 case SCARD_E_PROTO_MISMATCH:
127 return "SCARD_E_PROTO_MISMATCH";
128 case SCARD_E_READ_ONLY_CARD:
129 return "SCARD_E_READ_ONLY_CARD";
130 case SCARD_E_READER_UNAVAILABLE:
131 return "SCARD_E_READER_UNAVAILABLE";
132 case SCARD_E_READER_UNSUPPORTED:
133 return "SCARD_E_READER_UNSUPPORTED";
134 case SCARD_E_SERVER_TOO_BUSY:
135 return "SCARD_E_SERVER_TOO_BUSY";
136 case SCARD_E_SERVICE_STOPPED:
137 return "SCARD_E_SERVICE_STOPPED";
138 case SCARD_E_SHARING_VIOLATION:
139 return "SCARD_E_SHARING_VIOLATION";
140 case SCARD_E_SYSTEM_CANCELLED:
141 return "SCARD_E_SYSTEM_CANCELLED";
142 case SCARD_E_TIMEOUT:
143 return "SCARD_E_TIMEOUT";
144 case SCARD_E_UNEXPECTED:
145 return "SCARD_E_UNEXPECTED";
146 case SCARD_E_UNKNOWN_CARD:
147 return "SCARD_E_UNKNOWN_CARD";
148 case SCARD_E_UNKNOWN_READER:
149 return "SCARD_E_UNKNOWN_READER";
150 case SCARD_E_UNKNOWN_RES_MNG:
151 return "SCARD_E_UNKNOWN_RES_MNG";
152 case SCARD_E_UNSUPPORTED_FEATURE:
153 return "SCARD_E_UNSUPPORTED_FEATURE";
154 case SCARD_E_WRITE_TOO_MANY:
155 return "SCARD_E_WRITE_TOO_MANY";
156 case SCARD_F_COMM_ERROR:
157 return "SCARD_F_COMM_ERROR";
158 case SCARD_F_INTERNAL_ERROR:
159 return "SCARD_F_INTERNAL_ERROR";
160 case SCARD_F_UNKNOWN_ERROR:
161 return "SCARD_F_UNKNOWN_ERROR";
162 case SCARD_F_WAITED_TOO_LONG:
163 return "SCARD_F_WAITED_TOO_LONG";
164 case SCARD_P_SHUTDOWN:
165 return "SCARD_P_SHUTDOWN";
166 case SCARD_S_SUCCESS:
167 return "SCARD_S_SUCCESS";
168 case SCARD_W_CANCELLED_BY_USER:
169 return "SCARD_W_CANCELLED_BY_USER";
170 case SCARD_W_CACHE_ITEM_NOT_FOUND:
171 return "SCARD_W_CACHE_ITEM_NOT_FOUND";
172 case SCARD_W_CACHE_ITEM_STALE:
173 return "SCARD_W_CACHE_ITEM_STALE";
174 case SCARD_W_CACHE_ITEM_TOO_BIG:
175 return "SCARD_W_CACHE_ITEM_TOO_BIG";
176 case SCARD_W_CARD_NOT_AUTHENTICATED:
177 return "SCARD_W_CARD_NOT_AUTHENTICATED";
178 case SCARD_W_CHV_BLOCKED:
179 return "SCARD_W_CHV_BLOCKED";
181 return "SCARD_W_EOF";
182 case SCARD_W_REMOVED_CARD:
183 return "SCARD_W_REMOVED_CARD";
184 case SCARD_W_RESET_CARD:
185 return "SCARD_W_RESET_CARD";
186 case SCARD_W_SECURITY_VIOLATION:
187 return "SCARD_W_SECURITY_VIOLATION";
188 case SCARD_W_UNPOWERED_CARD:
189 return "SCARD_W_UNPOWERED_CARD";
190 case SCARD_W_UNRESPONSIVE_CARD:
191 return "SCARD_W_UNRESPONSIVE_CARD";
192 case SCARD_W_UNSUPPORTED_CARD:
193 return "SCARD_W_UNSUPPORTED_CARD";
194 case SCARD_W_WRONG_CHV:
195 return "SCARD_W_WRONG_CHV";
201 static std::wstring err2wstr(LONG code)
203 auto str = err2str(code);
204 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
205 return converter.from_bytes(str);
209 static bool test_listreadergroups(SCARDCONTEXT hContext) {
210 auto rc = SCardListReaderGroupsA(hContext, &groups, &foobar);
211 rc = SCardListReaderGroupsW(hContext, &groups, &foobar);
215 static bool test_valid(SCARDCONTEXT context)
217 auto rc = SCardIsValidContext(context);
219 std::cerr <<
"SCardIsValidContext failed with " << err2str(rc) << std::endl;
223 static bool test_list_readers_a(SCARDCONTEXT context)
225 for (
auto cur : listA)
227 LPSTR mszReaders =
nullptr;
228 DWORD chReaders = SCARD_AUTOALLOCATE;
229 auto rc = SCardListReadersA(context, cur,
reinterpret_cast<LPSTR
>(&mszReaders), &chReaders);
234 if (rc != SCARD_S_SUCCESS)
236 std::cerr <<
"SCardListReadersA [" << cur <<
"] failed with " << err2str(rc)
241 auto start = mszReaders;
242 auto end = &mszReaders[chReaders];
244 std::cout <<
"SCardListReadersA [" << cur <<
"] " << chReaders <<
" [";
247 std::cout << start <<
", ";
248 start += strnlen(start, chReaders) + 2;
250 std::cout <<
"]" << std::endl;
252 SCardFreeMemory(context, mszReaders);
258 static bool test_list_readers_w(SCARDCONTEXT context)
260 for (
auto cur : listW)
262 LPWSTR mszReaders =
nullptr;
263 DWORD chReaders = SCARD_AUTOALLOCATE;
265 SCardListReadersW(context, cur,
reinterpret_cast<LPWSTR
>(&mszReaders), &chReaders);
270 if (rc != SCARD_S_SUCCESS)
272 std::wcerr << L
"SCardListReadersW [" << cur << L
"] failed with " << err2wstr(rc)
277 auto start = mszReaders;
278 auto end = &mszReaders[chReaders];
280 std::wcout << L
"SCardListReadersW [" << cur << L
"] " << chReaders << L
" [";
283 std::wcout << start << L
", ";
284 start += wcsnlen(start, chReaders) + 2;
286 std::wcout << L
"]" << std::endl;
288 SCardFreeMemory(context, mszReaders);
294 static bool test_list_reader_groups_a(SCARDCONTEXT context)
296 LPSTR mszReaders =
nullptr;
297 DWORD chReaders = SCARD_AUTOALLOCATE;
298 auto rc = SCardListReaderGroupsA(context,
reinterpret_cast<LPSTR
>(&mszReaders), &chReaders);
299 if (rc != SCARD_S_SUCCESS)
301 std::cerr <<
"SCardListReaderGroupsA failed with " << err2str(rc) << std::endl;
305 auto start = mszReaders;
306 auto end = &mszReaders[chReaders];
308 std::cout <<
"SCardListReaderGroupsA " << chReaders <<
" [";
311 std::cout << start <<
", ";
312 start += strnlen(start, chReaders) + 2;
314 std::cout <<
"]" << std::endl;
316 SCardFreeMemory(context, mszReaders);
321 static bool test_list_reader_groups_w(SCARDCONTEXT context)
323 LPWSTR mszReaders =
nullptr;
324 DWORD chReaders = SCARD_AUTOALLOCATE;
325 auto rc = SCardListReaderGroupsW(context,
reinterpret_cast<LPWSTR
>(&mszReaders), &chReaders);
326 if (rc != SCARD_S_SUCCESS)
328 std::wcerr << L
"SCardListReaderGroupsW failed with " << err2wstr(rc) << std::endl;
332 auto start = mszReaders;
333 auto end = &mszReaders[chReaders];
335 std::wcout << L
"SCardListReaderGroupsW " << chReaders << L
" [";
338 std::wcout << start << L
", ";
339 start += wcsnlen(start, chReaders) + 2;
341 std::wcout << L
"]" << std::endl;
343 SCardFreeMemory(context, mszReaders);
348 static bool test_introduce_forget_reader_groups_a(SCARDCONTEXT context)
350 LPSTR group =
"somefancygroup";
352 auto rc = SCardIntroduceReaderGroupA(context, group);
353 if (rc != SCARD_S_SUCCESS)
355 std::cerr <<
"SCardIntroduceReaderGroupA failed with " << err2str(rc) << std::endl;
360 rc = SCardForgetReaderGroupA(context, group);
361 if (rc != SCARD_S_SUCCESS)
363 std::cerr <<
"SCardForgetReaderGroupA failed with " << err2str(rc) << std::endl;
370 static bool test_introduce_forget_reader_groups_w(SCARDCONTEXT context)
372 LPWSTR group = L
"somefancygroup";
374 auto rc = SCardIntroduceReaderGroupW(context, group);
375 if (rc != SCARD_S_SUCCESS)
377 std::cerr <<
"SCardIntroduceReaderGroupW failed with " << err2str(rc) << std::endl;
382 rc = SCardForgetReaderGroupW(context, group);
383 if (rc != SCARD_S_SUCCESS)
385 std::cerr <<
"SCardForgetReaderGroupW failed with " << err2str(rc) << std::endl;
392 static bool test_introduce_forget_reader_a(SCARDCONTEXT context)
394 LPSTR reader =
"somefancygroup";
395 LPSTR device =
"otherfancy";
397 auto rc = SCardIntroduceReaderA(context, reader, device);
398 if (rc != SCARD_S_SUCCESS)
400 std::cerr <<
"SCardIntroduceReaderA failed with " << err2str(rc) << std::endl;
405 rc = SCardForgetReaderA(context, reader);
406 if (rc != SCARD_S_SUCCESS)
408 std::cerr <<
"SCardForgetReaderA failed with " << err2str(rc) << std::endl;
415 static bool test_introduce_forget_reader_w(SCARDCONTEXT context)
417 LPWSTR reader = L
"somefancygroup";
418 LPWSTR device = L
"otherfancy";
420 auto rc = SCardIntroduceReaderW(context, reader, device);
421 if (rc != SCARD_S_SUCCESS)
423 std::cerr <<
"SCardIntroduceReaderW failed with " << err2str(rc) << std::endl;
428 rc = SCardForgetReaderW(context, reader);
429 if (rc != SCARD_S_SUCCESS)
431 std::cerr <<
"SCardForgetReaderW failed with " << err2str(rc) << std::endl;
438 static bool test_list_cards_a(SCARDCONTEXT context)
440 DWORD chCards = SCARD_AUTOALLOCATE;
441 LPSTR mszCards =
nullptr;
443 SCardListCardsA(context,
nullptr,
nullptr, 0,
reinterpret_cast<LPSTR
>(&mszCards), &chCards);
444 if (rc != SCARD_S_SUCCESS)
446 std::cerr <<
"SCardListCardsA failed with " << err2str(rc) << std::endl;
450 auto start = mszCards;
451 auto end = &mszCards[chCards];
452 std::cout <<
"SCardListCardsA " << chCards <<
" [";
455 std::cout << start <<
", ";
456 start += strnlen(start, chCards) + 2;
458 std::cout <<
"]" << std::endl;
463 static bool test_list_cards_w(SCARDCONTEXT context)
465 DWORD chCards = SCARD_AUTOALLOCATE;
466 LPWSTR mszCards =
nullptr;
467 auto rc = SCardListCardsW(context,
nullptr,
nullptr, 0,
reinterpret_cast<LPWSTR
>(&mszCards),
469 if (rc != SCARD_S_SUCCESS)
471 std::cerr <<
"SCardListCardsW failed with " << err2str(rc) << std::endl;
475 auto start = mszCards;
476 auto end = &mszCards[chCards];
477 std::cout <<
"SCardListCardsW " << chCards <<
" [";
480 std::wcout << start << L
", ";
481 start += wcsnlen(start, chCards) + 2;
483 std::cout <<
"]" << std::endl;
488 static bool test_cache_a(SCARDCONTEXT context)
490 BYTE wdata[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
491 const DWORD wdatalen =
sizeof(wdata);
493 DWORD datalen =
sizeof(data);
494 LPSTR name =
"testdata";
497 auto rc = SCardWriteCacheA(context, &
id, 0, name, wdata, wdatalen);
498 if (rc != SCARD_S_SUCCESS)
500 std::cerr <<
"SCardWriteCacheA failed with " << err2str(rc) << std::endl;
504 rc = SCardReadCacheA(context, &
id, 0, name, data, &datalen);
505 if (rc != SCARD_S_SUCCESS)
507 std::cerr <<
"SCardReadCacheA failed with " << err2str(rc) << std::endl;
511 if (wdatalen != datalen)
513 std::cerr <<
"SCardWriteCacheA wrote " << wdatalen <<
"bytes, SCardReadCacheA read "
514 << datalen <<
"bytes" << std::endl;
518 if (memcmp(wdata, data, wdatalen) != 0)
520 std::cerr <<
"SCardWriteCacheA / SCardReadCacheA data corruption detected" << std::endl;
527 static bool test_cache_w(SCARDCONTEXT context)
529 BYTE wdata[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
530 const DWORD wdatalen =
sizeof(wdata);
532 DWORD datalen =
sizeof(data);
533 LPWSTR name = L
"testdata";
536 auto rc = SCardWriteCacheW(context, &
id, 0, name, wdata, wdatalen);
537 if (rc != SCARD_S_SUCCESS)
539 std::cerr <<
"SCardWriteCacheW failed with " << err2str(rc) << std::endl;
543 rc = SCardReadCacheW(context, &
id, 0, name, data, &datalen);
544 if (rc != SCARD_S_SUCCESS)
546 std::cerr <<
"SCardReadCacheW failed with " << err2str(rc) << std::endl;
550 if (wdatalen != datalen)
552 std::cerr <<
"SCardReadCacheW wrote " << wdatalen <<
"bytes, SCardReadCacheW read "
553 << datalen <<
"bytes" << std::endl;
557 if (memcmp(wdata, data, wdatalen) != 0)
559 std::cerr <<
"SCardReadCacheW / SCardReadCacheW data corruption detected" << std::endl;
566 static bool test_reader_icon_a(SCARDCONTEXT context)
568 LPSTR name =
"Gemalto PC Twin Reader 00 00\0\0";
569 LPBYTE pbIcon =
nullptr;
570 DWORD cbIcon = SCARD_AUTOALLOCATE;
572 auto rc = SCardGetReaderIconA(context, name,
reinterpret_cast<LPBYTE
>(&pbIcon), &cbIcon);
573 SCardFreeMemory(context, pbIcon);
574 if (rc != SCARD_S_SUCCESS)
576 std::cerr <<
"SCardGetReaderIconA failed with " << err2str(rc) << std::endl;
583 static bool test_reader_icon_w(SCARDCONTEXT context)
585 LPWSTR name = L
"Gemalto PC Twin Reader 00 00\0\0";
586 LPBYTE pbIcon =
nullptr;
587 DWORD cbIcon = SCARD_AUTOALLOCATE;
589 auto rc = SCardGetReaderIconW(context, name,
reinterpret_cast<LPBYTE
>(&pbIcon), &cbIcon);
590 SCardFreeMemory(context, pbIcon);
591 if (rc != SCARD_S_SUCCESS)
593 std::cerr <<
"SCardGetReaderIconW failed with " << err2str(rc) << std::endl;
600 static bool test_locate_cards_a(SCARDCONTEXT context)
602 LPSTR name =
"Gemalto PC Twin Reader 00 00\0\0";
605 auto rc = SCardLocateCardsA(context, name, rgReaderStates, ARRAYSIZE(rgReaderStates));
606 if (rc != SCARD_S_SUCCESS)
608 std::cerr <<
"SCardLocateCardsA failed with " << err2str(rc) << std::endl;
615 static bool test_locate_cards_w(SCARDCONTEXT context)
617 LPWSTR name = L
"Gemalto PC Twin Reader 00 00\0\0";
620 auto rc = SCardLocateCardsW(context, name, rgReaderStates, ARRAYSIZE(rgReaderStates));
621 if (rc != SCARD_S_SUCCESS)
623 std::cerr <<
"SCardLocateCardsW failed with " << err2str(rc) << std::endl;
630 static bool test_locate_cards_by_atr_a(SCARDCONTEXT context)
635 auto rc = SCardLocateCardsByATRA(context, rgAtrMasks, ARRAYSIZE(rgAtrMasks), rgReaderStates,
636 ARRAYSIZE(rgReaderStates));
637 if (rc != SCARD_S_SUCCESS)
639 std::cerr <<
"SCardLocateCardsByATRA failed with " << err2str(rc) << std::endl;
646 static bool test_locate_cards_by_atr_w(SCARDCONTEXT context)
651 auto rc = SCardLocateCardsByATRW(context, rgAtrMasks, ARRAYSIZE(rgAtrMasks), rgReaderStates,
652 ARRAYSIZE(rgReaderStates));
653 if (rc != SCARD_S_SUCCESS)
655 std::cerr <<
"SCardLocateCardsByATRW failed with " << err2str(rc) << std::endl;
662 static bool test_devicetype_id_a(SCARDCONTEXT context)
665 LPSTR name =
"testdata";
668 auto rc = SCardGetDeviceTypeIdA(context, name, &type);
669 if (rc != SCARD_S_SUCCESS)
671 std::cerr <<
"SCardGetDeviceTypeIdA failed with " << err2str(rc) << std::endl;
678 static bool test_devicetype_id_w(SCARDCONTEXT context)
681 LPWSTR name = L
"testdata";
684 auto rc = SCardGetDeviceTypeIdW(context, name, &type);
685 if (rc != SCARD_S_SUCCESS)
687 std::cerr <<
"SCardGetDeviceTypeIdW failed with " << err2str(rc) << std::endl;
694 static bool test_transmitcount(SCARDHANDLE handle)
697 LPWSTR name = L
"testdata";
700 auto rc = SCardGetTransmitCount(handle, &count);
701 if (rc != SCARD_S_SUCCESS)
703 std::cerr <<
"SCardGetTransmitCount failed with " << err2str(rc) << std::endl;
706 std::cout <<
"SCardGetTransmitCount() " << count << std::endl;
710 static bool test_status_a(SCARDHANDLE handle)
713 LPWSTR name = L
"testdata";
725 static bool test_status_w(SCARDHANDLE handle)
728 LPWSTR name = L
"testdata";
740 static bool test_get_attrib(SCARDCONTEXT context, SCARDHANDLE handle)
742 DWORD attrlen = SCARD_AUTOALLOCATE;
743 LPBYTE attr =
nullptr;
746 SCardGetAttrib(handle, SCARD_ATTR_ATR_STRING,
reinterpret_cast<LPBYTE
>(&attr), &attrlen);
747 if (rc != SCARD_S_SUCCESS)
749 std::cerr <<
"SCardGetAttrib failed with " << err2str(rc) << std::endl;
752 std::cout <<
"SCardGetAttrib [" << attrlen <<
"]: " << (
char*)attr << std::endl;
753 SCardFreeMemory(context, attr);
758 static bool test_set_attrib(SCARDCONTEXT context, SCARDHANDLE handle)
760 DWORD attrlen = SCARD_AUTOALLOCATE;
761 BYTE attr[] =
"0123456789";
763 auto rc = SCardSetAttrib(handle, SCARD_ATTR_SUPRESS_T1_IFS_REQUEST, attr, ARRAYSIZE(attr));
764 if (rc != SCARD_S_SUCCESS)
766 std::cerr <<
"SCardSetAttrib failed with " << err2str(rc) << std::endl;
769 std::cout <<
"SCardSetAttrib [" << attrlen <<
"]: " << (
char*)attr << std::endl;
770 SCardFreeMemory(context, attr);
777 std::cout <<
"Hello World!" << std::endl;
780 auto scopes = { SCARD_SCOPE_USER, SCARD_SCOPE_SYSTEM };
781 for (
auto scope : scopes)
783 SCARDCONTEXT context;
784 auto rc = SCardEstablishContext(scope,
nullptr,
nullptr, &context);
785 if (rc != SCARD_S_SUCCESS)
787 std::cerr <<
"SCardEstablishContext [" << scope2str(scope) <<
"] failed with "
788 << err2str(rc) << std::endl;
792 std::cerr <<
"SCardEstablishContext [" << scope2str(scope) <<
"] success"
797 test_list_reader_groups_a(context);
798 test_list_reader_groups_w(context);
800 test_list_readers_a(context);
801 test_list_readers_w(context);
803 test_list_cards_a(context);
804 test_list_cards_w(context);
806 test_introduce_forget_reader_groups_a(context);
807 test_introduce_forget_reader_groups_w(context);
809 test_introduce_forget_reader_a(context);
810 test_introduce_forget_reader_w(context);
813 test_locate_cards_a(context);
814 test_locate_cards_w(context);
816 test_locate_cards_by_atr_a(context);
817 test_locate_cards_by_atr_w(context);
819 test_cache_a(context);
820 test_cache_w(context);
822 test_reader_icon_a(context);
823 test_reader_icon_w(context);
825 test_devicetype_id_a(context);
826 test_devicetype_id_w(context);
836 SCARDHANDLE handle = 0;
838 DWORD chReaders = SCARD_AUTOALLOCATE;
840 LONG status = SCardListReadersA(
841 context,
nullptr,
reinterpret_cast<LPSTR
>(&mszReaders), &chReaders);
842 if (status == SCARD_S_SUCCESS)
843 status = SCardConnectA(context, mszReaders, SCARD_SHARE_SHARED,
844 SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1 |
845 SCARD_PROTOCOL_Tx | SCARD_PROTOCOL_RAW,
847 SCardFreeMemory(context, mszReaders);
848 if (status != SCARD_S_SUCCESS)
850 std::cerr <<
"SCardConnectA ["
851 <<
"] failed with " << err2str(status) << std::endl;
855 test_status_a(handle);
856 test_status_w(handle);
857 test_get_attrib(context, handle);
858 test_set_attrib(context, handle);
859 test_transmitcount(handle);
861 status = SCardDisconnect(handle, 0);
864 std::cerr <<
"SCardDisconnect ["
865 <<
"] failed with " << err2str(status) << std::endl;
871 SCARDHANDLE handle = 0;
873 DWORD chReaders = SCARD_AUTOALLOCATE;
875 LONG status = SCardListReadersW(
876 context,
nullptr,
reinterpret_cast<LPWSTR
>(&mszReaders), &chReaders);
877 if (status == SCARD_S_SUCCESS)
878 status = SCardConnectW(context, mszReaders, SCARD_SHARE_SHARED,
879 SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1 |
880 SCARD_PROTOCOL_Tx | SCARD_PROTOCOL_RAW,
882 SCardFreeMemory(context, mszReaders);
884 if (status != SCARD_S_SUCCESS)
886 std::cerr <<
"SCardConnectW ["
887 <<
"] failed with " << err2str(status) << std::endl;
891 test_status_a(handle);
892 test_status_w(handle);
893 test_get_attrib(context, handle);
894 test_set_attrib(context, handle);
895 test_transmitcount(handle);
897 status = SCardDisconnect(handle, 0);
900 std::cerr <<
"SCardDisconnect ["
901 <<
"] failed with " << err2str(status) << std::endl;
906 rc = SCardReleaseContext(context);
907 if (rc != SCARD_S_SUCCESS)
909 std::cerr <<
"SCardReleaseContext [" << scope2str(scope) <<
"] failed with "
910 << err2str(rc) << std::endl;
917 std::cerr <<
"exception!!!!" << std::endl;