Example #1
0
        public int Transmit(byte[] sendBuffer, byte[] receiveBuffer)
        {
            SmartCardIORequest sendPci = SmartCardIORequest.T1;
            SmartCardIORequest recvPci = SmartCardIORequest.T1;
            uint   len = (uint)receiveBuffer.Length;
            IntPtr ptr = Marshal.AllocHGlobal((int)len);

            try {
                int ret = SCardTransmit(card, ref sendPci, sendBuffer, (uint)sendBuffer.Length, ref recvPci, ptr, ref len);
                if (ret != 0)
                {
                    throw SmartCardContext.ToException(ret);
                }
                //Console.Write("Transmit received {0} bytes: ", len);
                Marshal.Copy(ptr, receiveBuffer, 0, (int)len);
                //Console.WriteLine(BitConverter.ToString(receiveBuffer, 0, (int)len));
                return((int)len);
            } finally {
                Marshal.FreeHGlobal(ptr);
            }
        }
Example #2
0
 private static extern int SCardTransmit(IntPtr card, [MarshalAs(UnmanagedType.Struct)] ref SmartCardIORequest sendPci, [MarshalAs(UnmanagedType.LPArray)] byte[] sendBuffer, uint sendLen, [MarshalAs(UnmanagedType.Struct)] ref SmartCardIORequest recvPci, IntPtr recvBuffer, ref uint recvLen);