Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) PC/SC Get Card UIDSee more SCard ExamplesSends the APDU command to get a card's UID.
#include <C_CkSCardW.h> #include <C_CkBinDataW.h> void ChilkatSample(void) { HCkSCardW scard; BOOL success; HCkBinDataW bdRecv; int numBytes; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. scard = CkSCardW_Create(); // First establish a context to the PC/SC Resource Manager success = CkSCardW_EstablishContext(scard,L"user"); if (success == FALSE) { wprintf(L"%s\n",CkSCardW_lastErrorText(scard)); CkSCardW_Dispose(scard); return; } // Use your own smart card reader name here. success = CkSCardW_Connect(scard,L"ACS ACR122 0",L"shared",L"no_preference"); if (success == FALSE) { wprintf(L"%s\n",CkSCardW_lastErrorText(scard)); CkSCardW_Dispose(scard); return; } wprintf(L"Connected reader: %s\n",CkSCardW_connectedReader(scard)); wprintf(L"Active protocol: %s\n",CkSCardW_activeProtocol(scard)); wprintf(L"ATR: %s\n",CkSCardW_cardAtr(scard)); wprintf(L"Reader Status: %s\n",CkSCardW_readerStatus(scard)); // Send the APDU command 0xFF, 0xCA, 0x00, 0x00, 0x00 bdRecv = CkBinDataW_Create(); success = CkSCardW_TransmitHex(scard,CkSCardW_activeProtocol(scard),L"FFCA000000",bdRecv,32); if (success == TRUE) { wprintf(L"Received: %s\n",CkBinDataW_getEncoded(bdRecv,L"hex")); // The UID is the returned data without the final 2 bytes. numBytes = CkBinDataW_getNumBytes(bdRecv); if (numBytes > 2) { wprintf(L"UID: %s\n",CkBinDataW_getEncodedChunk(bdRecv,0,numBytes - 2,L"hex")); } } else { wprintf(L"%s\n",CkSCardW_lastErrorText(scard)); } // Disconnect from this reader. success = CkSCardW_Disconnect(scard,L"leave"); if (success == FALSE) { wprintf(L"%s\n",CkSCardW_lastErrorText(scard)); } // Applications should always release the context when finished. success = CkSCardW_ReleaseContext(scard); if (success == FALSE) { wprintf(L"%s\n",CkSCardW_lastErrorText(scard)); } CkSCardW_Dispose(scard); CkBinDataW_Dispose(bdRecv); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.