C# PC/SC求助 我是在WIN7下调试的

[复制链接]
查看11 | 回复1 | 2011-1-10 16:12:27 | 显示全部楼层 |阅读模式
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下是正常的
驱动有

回复

使用道具 举报

千问 | 2011-1-10 16:12:27 | 显示全部楼层
右键我的电脑管理 设备管理器 属于你手机的驱动是 不是问号。是的话更新 。自动更新不行的话 。一下我也说不出怎么解决。就是去网上下载个 驱动 安装版的 免安装版的都可以。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行