Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SCardTransmit (winscard)
 
.
Summary
The SCardTransmit function sends a service request to the smart card and expects to receive data back from the card.

C# Signature:

[DllImport("winscard.dll")]
static extern int SCardTransmit(int hCard, IntPtr pioSendPci, byte[] pbSendBuffer, int cbSendLength, SCARD_IO_REQUEST pioRecvPci,
        byte[] pbRecvBuffer, ref int pcbRecvLength);

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.

Sample Code:

// Paste here code for SCardEstablishContext, SCardConnect

[StructLayout(LayoutKind.Sequential)]
internal class SCARD_IO_REQUEST
   {
    internal uint dwProtocol;
    internal int cbPciLength;
    public SCARD_IO_REQUEST()
      {
    dwProtocol = 0;
      }
   }

[DllImport("kernel32.dll")]
private extern static IntPtr LoadLibrary(string lpFileName);

[DllImport("kernel32.dll")]
private extern static void FreeLibrary(IntPtr handle) ;

[DllImport("kernel32.dll")]
private extern static IntPtr GetProcAddress(IntPtr handle, string
procName);

//Get the address of Pci from "Winscard.dll".
private static IntPtr GetPciT0()
{
IntPtr handle = LoadLibrary("Winscard.dll") ;
IntPtr pci = GetProcAddress(handle, "g_rgSCardT0Pci") ;
FreeLibrary(handle) ;
return pci ;
}

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

Documentation

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).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions