public int phContext0 = -1;//建立的资源管理器上下文的句柄
public int MAX_RESPONSE =2*1024;//系统所有读卡器名称的长度
public string ReadListInfo = "";
int ContextHandle = 0, CardHandle = 0, ActiveProtocol = 0, ReaderCount = -1;
string ReaderList = string.Empty; //读卡机名称列表
SCARD_IO_REQUEST SendPci, RecvPci;
byte[] SelectAPDU = { 0x00, 0xA4, 0x04, 0x00, 0x10, 0xD1, 0x58, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00 };
byte[] ReadProfileAPDU = { 0x00, 0xca, 0x11, 0x00, 0x02, 0x00, 0x00 };
byte[] SelectRecvBytes = new byte[2]; //应回 90 00
int SelectRecvLength = 2;
byte[] ProfileRecvBytes = new byte[59]; //接收Profile的 Byte Array
int ProfileRecvLength = 59;
byte[] cReaderListName=new byte[1024];
public struct SCARD_IO_REQUEST
{
public int dwProtocol;
public int cbPciLength;
}
//引用 PC/SC(Personal Computer/Smart Card) API WinScard.dll
[DllImport("WinScard.dll")]
public static extern int SCardEstablishContext(uint dwScope,int nNotUsed1, int nNotUsed2, ref int phContext);
[DllImport("WinScard.dll")]
public static extern int SCardReleaseContext(int phContext);
[DllImport("WinScard.dll")]
public static extern int SCardConnect(int hContext, string cReaderName,uint dwShareMode, uint dwPrefProtocol, ref int phCard, ref int ActiveProtocol);
[DllImport("WinScard.dll")]
public static extern int SCardDisconnect(int hCard, int Disposition);
[DllImport("WinScard.dll")]
//public static extern int SCardListReaders(int hContext, string cGroups, byte[] cReaderLists, ref int nReaderCount);
public static extern int SCardListReaders(int hContext, string cGroups,ref string cReaderLists, ref int nReaderCount);
[DllImport("WinScard.dll")]
public static extern int SCardTransmit(int hCard,ref SCARD_IO_REQUEST pioSendPci, byte[] pbSendBuffer, int cbSendLength,ref SCARD_IO_REQUEST pioRecvPci, ref byte pbRecvBuffer, ref int pcbRecvLength);
public MainFrm()
{
InitializeComponent();
}
private void btClear_Click(object sender, EventArgs e)
{
rbReciever.Text = "";
}
private void MainFrm_Load(object sender, EventArgs e)
{
//建立 Smart Card API
int a = SCardEstablishContext(0, 0, 0, ref ContextHandle);
if (a != 0)
{
MessageBox.Show("建立资源失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
int b = SCardListReaders(ContextHandle, null, ref ReaderList, ref ReaderCount);这行提示内存错误,但是在XP下是正常的
驱动有
|