哪位C#高手帮忙看一下啊,解释一下代码含义,感激不尽,下面的是部分代码。
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace pcscsample
{
public struct SCARD_IO_REQUEST
{
public int dwProtocol;
public int cbPciLength;
}
public partial class pcsc : Form
{
[DllImport("WinSCard.dll")]
public static extern int SCardEstablishContext(uint dwScope, IntPtr pvReserved1, IntPtr pvReserved2, out IntPtr phContext);
[DllImport("WinScard.dll")]
private static extern int SCardConnect(IntPtr hContext, string cReaderName, uint dwShareMode, uint dwPrefProtocol, ref int phCard, ref IntPtr ActiveProtocol);
[DllImport("WinScard.dll", EntryPoint = "SCardListReadersA", CharSet = CharSet.Ansi)]
private static extern int SCardListReaders(IntPtr hContext, string mszGroups, ref StringBuilder mszReaders, ref int pcchReaders);
[DllImport("WinScard.dll")]
private 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);
[DllImport("WinScard.dll")]
private static extern int SCardDisconnect(int hCard, int Disposition);
[DllImport("WinScard.dll")]
private static extern int SCardReleaseContext(IntPtr phContext);
private const long SCARD_PROTOCOL_T1 = 0x02;
private const uint SCARD_PROTOCOL_T0 = 0x01;
private const long SCARD_S_SUCCESS = 0;
private const uint SCARD_SCOPE_USER = 0;
private const uint SCARD_SHARE_SHARED = 2;
private IntPtr hContext = IntPtr.Zero;
private int hCard = 0;
private string[] readerNameArr;
private string readerNameSelected;
public pcsc()
{
InitializeComponent();
} 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace pcscsample
{
public struct SCARD_IO_REQUEST
{
public int dwProtocol;
public int cbPciLength;
}
public partial class pcsc : Form
{
[DllImport("WinSCard.dll")]
public static extern int SCardEstablishContext(uint dwScope, IntPtr pvReserved1, IntPtr pvReserved2, out IntPtr phContext);
[DllImport("WinScard.dll")]
private static extern int SCardConnect(IntPtr hContext, string cReaderName, uint dwShareMode, uint dwPrefProtocol, ref int phCard, ref IntPtr ActiveProtocol);
[DllImport("WinScard.dll", EntryPoint = "SCardListReadersA", CharSet = CharSet.Ansi)]
private static extern int SCardListReaders(IntPtr hContext, string mszGroups, ref StringBuilder mszReaders, ref int pcchReaders);
[DllImport("WinScard.dll")]
private 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);
[DllImport("WinScard.dll")]
private static extern int SCardDisconnect(int hCard, int Disposition);
[DllImport("WinScard.dll")]
private static extern int SCardReleaseContext(IntPtr phContext);
private const long SCARD_PROTOCOL_T1 = 0x02;
private const uint SCARD_PROTOCOL_T0 = 0x01;
private const long SCARD_S_SUCCESS = 0;
private const uint SCARD_SCOPE_USER = 0;
private const uint SCARD_SHARE_SHARED = 2;
private IntPtr hContext = IntPtr.Zero;
private int hCard = 0;
private string[] readerNameArr;
private string readerNameSelected;
public pcsc()
{
InitializeComponent();
} 展开
展开全部
//声明结构变量
public struct SCARD_IO_REQUEST
{
public int dwProtocol;
public int cbPciLength;
}
//声明API函数的一些方法你查一下资料就行了
[DllImport("WinSCard.dll")]
public static extern int SCardEstablishContext(uint dwScope, IntPtr pvReserved1, IntPtr pvReserved2, out IntPtr phContext);
[DllImport("WinScard.dll")]
private static extern int SCardConnect(IntPtr hContext, string cReaderName, uint dwShareMode, uint dwPrefProtocol, ref int phCard, ref IntPtr ActiveProtocol);
[DllImport("WinScard.dll", EntryPoint = "SCardListReadersA", CharSet = CharSet.Ansi)]
private static extern int SCardListReaders(IntPtr hContext, string mszGroups, ref StringBuilder mszReaders, ref int pcchReaders);
[DllImport("WinScard.dll")]
private 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);
[DllImport("WinScard.dll")]
private static extern int SCardDisconnect(int hCard, int Disposition);
[DllImport("WinScard.dll")]
private static extern int SCardReleaseContext(IntPtr phContext);
//声明一些常量
private const long SCARD_PROTOCOL_T1 = 0x02;
private const uint SCARD_PROTOCOL_T0 = 0x01;
private const long SCARD_S_SUCCESS = 0;
private const uint SCARD_SCOPE_USER = 0;
private const uint SCARD_SHARE_SHARED = 2;
private IntPtr hContext = IntPtr.Zero;
private int hCard = 0;
private string[] readerNameArr;
private string readerNameSelected;
//类的构造函数
public pcsc()
{
InitializeComponent();
}
你去查一下API函数怎样用就行了
public struct SCARD_IO_REQUEST
{
public int dwProtocol;
public int cbPciLength;
}
//声明API函数的一些方法你查一下资料就行了
[DllImport("WinSCard.dll")]
public static extern int SCardEstablishContext(uint dwScope, IntPtr pvReserved1, IntPtr pvReserved2, out IntPtr phContext);
[DllImport("WinScard.dll")]
private static extern int SCardConnect(IntPtr hContext, string cReaderName, uint dwShareMode, uint dwPrefProtocol, ref int phCard, ref IntPtr ActiveProtocol);
[DllImport("WinScard.dll", EntryPoint = "SCardListReadersA", CharSet = CharSet.Ansi)]
private static extern int SCardListReaders(IntPtr hContext, string mszGroups, ref StringBuilder mszReaders, ref int pcchReaders);
[DllImport("WinScard.dll")]
private 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);
[DllImport("WinScard.dll")]
private static extern int SCardDisconnect(int hCard, int Disposition);
[DllImport("WinScard.dll")]
private static extern int SCardReleaseContext(IntPtr phContext);
//声明一些常量
private const long SCARD_PROTOCOL_T1 = 0x02;
private const uint SCARD_PROTOCOL_T0 = 0x01;
private const long SCARD_S_SUCCESS = 0;
private const uint SCARD_SCOPE_USER = 0;
private const uint SCARD_SHARE_SHARED = 2;
private IntPtr hContext = IntPtr.Zero;
private int hCard = 0;
private string[] readerNameArr;
private string readerNameSelected;
//类的构造函数
public pcsc()
{
InitializeComponent();
}
你去查一下API函数怎样用就行了
追问
哦,可以给个扣扣号吗,请教一下,谢谢
追答
1297802639
展开全部
DllImport:功能是提供从非托管DLL导出的函数的必要调用信息。
DllImport属性应用于方法,要求最少要提供包含入口点的dll的名称。
比如
[DllImport("WinScard.dll")]
private static extern int SCardReleaseContext(IntPtr phContext);
就是声明 来自WinScard这个库中的SCardReleaseContext函数, 这样在C#中你就能直接使用这个函数了。 (因为之前这个函数是外部dll中提供的,C#无法通过类的实例来调用,)
ps:WinScard.dll好像是提供访问智能卡设备的库。
DllImport属性应用于方法,要求最少要提供包含入口点的dll的名称。
比如
[DllImport("WinScard.dll")]
private static extern int SCardReleaseContext(IntPtr phContext);
就是声明 来自WinScard这个库中的SCardReleaseContext函数, 这样在C#中你就能直接使用这个函数了。 (因为之前这个函数是外部dll中提供的,C#无法通过类的实例来调用,)
ps:WinScard.dll好像是提供访问智能卡设备的库。
更多追问追答
追问
对,就是访问智能卡设备的库,现在我要通过C#来与卡连接,因为第一次接触这个东西,实在不知道怎么下手
追答
你得找智能卡厂商要 API接口说明,知道每个函数以及函数参数的意义,你才会知道怎么使用啊。
看你的代码,需要调用的函数都声明出来了,C#可以直接调用了,
比如这个方法 SCardConnect(IntPtr hContext, string cReaderName, uint dwShareMode, uint dwPrefProtocol, ref int phCard, ref IntPtr ActiveProtocol);
应该是连接智能卡的方法,但是参数怎么传你得看厂商的开发说明书了。
pcsc.SCardConnect(参数1,参数2.....)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-04-01
展开全部
i,将i初始化为0,如果i小于数组的位数,i就加1,并且执行中括号中的内容。
如果数组当前的项数不等于用户的属于,那么从数组中把这项删除,并将i减去1.
建议看看算法相关的书。这是程序里最常见的for循环。作用是遍历数组或者一些有二维结构的实体。
另外,团IDC网上有许多产品团购,便宜有口碑
如果数组当前的项数不等于用户的属于,那么从数组中把这项删除,并将i减去1.
建议看看算法相关的书。这是程序里最常见的for循环。作用是遍历数组或者一些有二维结构的实体。
另外,团IDC网上有许多产品团购,便宜有口碑
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询