Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than winscard, prefix the name with the module name and a period.
SCardTransmit (winscard)
.
C# Signature:
[StructLayout(LayoutKind.Sequential)]
public struct SCARD_IO_REQUEST
{
public UInt32 dwProtocol;
public UInt32 cbPciLength;
public int dwProtocol;
public int cbPciLength;
}
[DllImport("winscard.dll")]
public static extern int SCardTransmit(
IntPtr hCard,
ref SCARD_IO_REQUEST pioSendRequest,
ref byte SendBuff,
UInt32 SendBuffLen,
ref SCARD_IO_REQUEST pioRecvRequest,
out byte RecvBuff,
ref byte RecvBuff,
ref UInt32 RecvBuffLen
);
User-Defined Types:
None.
Notes:
None.
Tips & Tricks:
One may Get the SCARD_IO_REQUEST values which are defined as pointer to initialised data export in WinSCard.dll using the LoadLibrary and GetProcAddress pair.
If you use a struct rather than a class for SCARD_IO_REQUEST, don't forget to add "ref" to the pioRecvPci parameter in the signature. Alternatively, if you don't care about the returned protocol control information, change the pioRecvPci parameter to an "IntPtr" and pass "IntPtr.Zero" in as this parameter
Edit...
updated to better working signature (VS2010)...still need to establish context, and connect the card like in sample area, but this is an example of code that will read an iClass UID
private int GetUID(ref byte[] UID)
{
byte[] receivedUID = new byte[10];
UnsafeNativeMethods.SCARD_IO_REQUEST request = new UnsafeNativeMethods.SCARD_IO_REQUEST();
request.dwProtocol = 1; //SCARD_PROTOCOL_T1);
request.cbPciLength = System.Runtime.InteropServices.Marshal.SizeOf(typeof(UnsafeNativeMethods.SCARD_IO_REQUEST));
byte[] sendBytes = new byte[] { 0xFF, 0xCA, 0x00, 0x00, 0x00 }; //get UID command for iClass cards
int outBytes = receivedUID.Length;
int status = SCardTransmit(_hCard, ref request, ref sendBytes[0], (uint)sendBytes.Length, ref request, out receivedUID[0], ref outBytes);
int status = SCardTransmit(_hCard, ref request, ref sendBytes[0], sendBytes.Length, ref request, ref receivedUID[0], ref outBytes);
UID = receivedUID.Take(8).ToArray(); //only take the first 8, the last 2 bytes are not part of the UID of the card (iClass 2k cards...not sure about others)
return status;
}
Sample Code:
// Paste here code for SCardEstablishContext, SCardConnect
[DllImport("kernel32.dll", SetLastError=true)]
private extern static IntPtr LoadLibrary(string lpFileName);
[StructLayout(LayoutKind.Sequential)]
internal class SCARD_IO_REQUEST
{
internal uint dwProtocol;
internal int cbPciLength;
public SCARD_IO_REQUEST()
{
dwProtocol = 0;
}
}
// Paste here code for SCardDisconnect, pbRecvBuffer contains Answer as Byte[]
SCARD_IO_REQUEST ioRecv = new SCARD_IO_REQUEST();
byte[] pbRecvBuffer=new byte [255];
int pcbRecvLength=255;
byte[] pbSendBuffer = { 0xC0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00 }; // Example Cla,Ins,P1,P2,P3,DataIN (Select MF)
int cbSendLength=pbSendBuffer.Length;
ioRecv.cbPciLength = 255;
IntPtr SCARD_PCI_T0 = PCSC.GetPciT0();
uint errors=SCardTransmit(nCard, SCARD_PCI_T0, pbSendBuffer, cbSendLength, ioRecv, pbRecvBuffer, ref pcbRecvLength);
// Paste here code for SCardDisconnect, pbRecvBuffer contains Answer as Byte[]
Alternative Managed API:
TODO
Alternative Managed API:
TODO
The SCardTransmit function sends a service request to the smart card and expects to receive data back from the card.
12/17/2015 2:53:28 AM - -88.98.38.185
TODO - a short description
3/16/2007 8:35:59 AM - -204.124.82.48
The LoadLibrary API maps the specified DLL file into the address space of the calling process.
1/15/2020 12:35:28 AM - -62.4.65.26
The GetProcAddress API
3/2/2022 7:31:41 PM - -78.86.32.130
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).