2012-04-19 53 views
-1

我在Windows MFC中编写了一个Java智能卡应用程序。如何查找所连接智能卡的驱动器名称(名称显示在“我的电脑”中)。例如。一旦我连接智能卡(即使它是智能卡,它将作为存储卡),它将以“**可移动磁盘(F:)**”的形式出现。我可以使用SCardConnect功能连接到智能卡。从SCardConnect函数的句柄返回,我可以获取驱动器名称。获取智能卡的驱动器名称

或者有什么方法可以找出某个特定的驱动器是否为智能卡。即。我们可以很容易地找到机器中的可移动磁盘,并从中找出它是否是智能卡。

预先感谢

+0

你的想法是太糟糕了。我有两个智能卡读卡器,第一个内部USB读卡器和戴尔智能卡键盘。在我的应用程序中,我测试了很多智能卡,从未看到它们充当可移动磁盘。 – Xearinox 2012-05-20 21:29:41

+0

我正在谈论Java smard卡,它可以用作手机中的加密卡和存储卡。在移动设备中,它将充当存储卡,但对于移动应用程序,它也将充当java智能卡。我正在开发使用智能卡的Android手机应用程序。在系统中它会检测为存储卡。希望你在谈论其他类型的智能卡 – DAC84 2012-05-21 14:24:49

回答

7

我已经写代码来枚举智能卡设备,在C;这里是我使用的代码;

干杯, 精读

int findDevice(){ 
hContext = NULL; 

log("\nSearching for the following device: XXX eKrypto Pinpad\n"); 

//Get a context to the resource manager 
lReturn = SCardEstablishContext(SCARD_SCOPE_USER,NULL,NULL,&hContext); 
log("Context established.\n"); 
if(lReturn != SCARD_S_SUCCESS){ 
    logBytes("SCardEstablishContext failed with error: ", (byte *)&lReturn, sizeof(LONG)); 
    return 0; 
} 

contextEstablished = true; 

//Get the readers list 
DWORD chReaders = 250; 
lReturn = SCardListReaders(hContext,NULL,readerNames,&chReaders); 
log("Reader List obtained.\n"); 
if(lReturn != SCARD_S_SUCCESS){ 
    logBytes(" SCardListReaders failed with error: \n", (byte *)&lReturn, sizeof(LONG)); 
    return 0; 
} 

//Search for device 
char *pReaders = readerNames; 
log(pReaders); 
while(strlen(pReaders) != 0 && deviceFound == false){ 
    if(!memcmp(pReaders, "ETS eKrypto Pinpad", 18)){ 
     deviceFound = true; 
     memcpy(currentReader, pReaders, strlen(pReaders)); 
    } 
    pReaders += strlen (pReaders)+1; 
} 
if(deviceFound == false){ 
    log(" Specified ETS device not found\n"); 
    return 0; 
} 

log(" Successful\n"); 
return 1; 
}