全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2969
推到 Plurk!
推到 Facebook!

取得PCSC讀卡機清單

 
juitsung
一般會員


發表:4
回覆:2
積分:1
註冊:2003-03-31

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-07-21 17:03:08 IP:114.44.xxx.xxx 訂閱
//---------------------------------------------------------------------------
bool __fastcall GetReaderList()
{
int ret = 0;
unsigned long pcchReaders = 0;
LPTSTR mszReaders = NULL;
TStringList *readers;
ret = SCardEstablishContext(0, 0, 0, &_ContextHandle);
if(ret != SCARD_S_SUCCESS)
{
String msg = "Failed SCardEstablishContext! " GetErrorCodeDescription(ret);
throw(Exception(msg));
return false;
}
ret = SCardListReaders(_ContextHandle, NULL, NULL, &pcchReaders);
if (ret != SCARD_S_SUCCESS) // 有錯誤
{
Application->NormalizeTopMosts();
#ifdef _DELPHI_STRING_UNICODE
String msg = L"Can't list PC/SC Smart Card Readers! " GetErrorCodeDescription(ret);
Application->MessageBox(msg.w_str(),
L"WARRING", MB_OKCANCEL);
#else
Application->MessageBox(
GetErrorCodeDescription(ret),
"WARRING", MB_OKCANCEL);
#endif
Application->RestoreTopMosts();
return false;
}
// 取得讀卡機資訊的字串長度
ret = SCardListReaders(_ContextHandle, NULL, NULL, &pcchReaders);
if (ret != SCARD_S_SUCCESS)
{ // 有錯誤
String msg = GetErrorCodeDescription(ret);
throw(Exception(msg));
return false;
}
try
{
TStringList *readers = new TStringList();
mszReaders = (LPTSTR)malloc(pcchReaders);
// 取得系統讀卡機資訊的字串
ret = SCardListReaders(_ContextHandle, NULL, mszReaders, &pcchReaders);
if (ret == SCARD_S_SUCCESS)
{
LPTSTR readerName = mszReaders;
int readerNumber = 0;
// 拆解字串
while((*readerName != '\0') && (readerNumber < MAX_READER_NUMBER))
{
readers->Add((LPCTSTR)readerName);
readerNumber ;
readerName = lstrlen(readerName) 1;
}
return true;
}
}
__finally
{
delete readers;
free(mszReaders);
}
return true;
}
//---------------------------------------------------------------------------
AnsiString __fastcall GetFormatedErrorCode(int nErrCode)
{
AnsiString sErrString;
sErrString.sprintf("0xX", nErrCode);
return sErrString;
}
//---------------------------------------------------------------------------
String __fastcall GetErrorCodeDescription(int nErrCode)
{
String sErrCode;
String sErrString;
sErrCode = GetFormatedErrorCode(nErrCode);
if(sErrCode == "80100001")
sErrString = "Internal Error";
else if(sErrCode == "0x80100002")
sErrString = "Cancelled";
else if(sErrCode == "0x80100003")
sErrString = "Invalid Handle";
else if(sErrCode == "0x80100004")
sErrString = "Invalid Parameter";
else if(sErrCode == "0x80100005")
sErrString = "Invalid Target";
else if(sErrCode == "0x80100006")
sErrString = "No Memory";
else if(sErrCode == "0x80100007")
sErrString = "Waited Too Long";
else if(sErrCode == "0x80100008")
sErrString = "Insufficient Buffer";
else if(sErrCode == "0x80100009")
sErrString = "Unknown Reader";
else if(sErrCode == "0x8010000A")
sErrString = "Timeout";
else if(sErrCode == "0x8010000B")
sErrString = "Sharing Violation";
else if(sErrCode == "0x8010000C")
sErrString = "No Smart Card";
else if(sErrCode == "0x8010000D")
sErrString = "Unknown Card";
else if(sErrCode == "0x8010000E")
sErrString = "Can't Dispose";
else if(sErrCode == "0x8010000F")
sErrString = "Proto Mismatch";
else if(sErrCode == "0x80100010")
sErrString = "Not Ready";
else if(sErrCode == "0x80100011")
sErrString = "Invalid Value";
else if(sErrCode == "0x80100012")
sErrString = "System Cancelled";
else if(sErrCode == "0x80100013")
sErrString = "Comm Error";
else if(sErrCode == "0x80100014")
sErrString = "Unknown Error";
else if(sErrCode == "0x80100015")
sErrString = "Invalid ATR";
else if(sErrCode == "0x80100016")
sErrString = "Not Transacted";
else if(sErrCode == "0x80100017")
sErrString = "Reader Unavailable";
else if(sErrCode == "0x80100018")
sErrString = "Shutdown";
else if(sErrCode == "0x80100019")
sErrString = "PCI Too Small";
else if(sErrCode == "0x8010001A")
sErrString = "Reader Unsupported";
else if(sErrCode == "0x8010001B")
sErrString = "Duplicate Reader";
else if(sErrCode == "0x8010001C")
sErrString = "Card Unsupported";
else if(sErrCode == "0x8010001D")
sErrString = "No Service";
else if(sErrCode == "0x8010001E")
sErrString = "Service Stopped";
else if(sErrCode == "0x80100065")
sErrString = "Unsupported Card";
else if(sErrCode == "0x80100066")
sErrString = "Unresponsive Card";
else if(sErrCode == "0x80100067")
sErrString = "Unpowered Card";
else if(sErrCode == "0x80100068")
sErrString = "Reset Card";
else if(sErrCode == "0x80100069")
sErrString = "Removed Card";
else
sErrString = "Unknown PC/SC Error Code - No Further Information Is Available.";
return sErrString;
}
編輯記錄
juitsung 重新編輯於 2010-07-21 17:04:28, 註解 無‧
juitsung 重新編輯於 2010-07-21 17:04:45, 註解 無‧
juitsung 重新編輯於 2010-07-21 17:06:10, 註解 無‧
juitsung 重新編輯於 2010-07-21 17:08:02, 註解 無‧
juitsung 重新編輯於 2010-07-21 17:15:55, 註解 無‧
系統時間:2017-10-21 7:37:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!