/// <summary>
        /// Initializes a new instance of the <see cref="SCardReaderState"/> class.
        /// </summary>
        public SCardReaderState()
        {
            switch (Platform.Type)
            {
            case PlatformType.Windows:
                _winscardRstate = new WINDOWS_SCARD_READERSTATE {
                    // initialize embedded array
                    rgbAtr = new byte[WinSCardAPI.MAX_ATR_SIZE],
                    cbAtr  = WinSCardAPI.MAX_ATR_SIZE
                };
                break;

            case PlatformType.Linux:
                _linuxRstate = new LINUX_SCARD_READERSTATE {
                    // initialize embedded array
                    rgbAtr = new byte[PCSCliteLinux.MAX_ATR_SIZE],
                    cbAtr  = (IntPtr)PCSCliteLinux.MAX_ATR_SIZE
                };
                break;

            case PlatformType.MacOSX:
                _macosxRstate = new MACOSX_SCARD_READERSTATE {
                    // initialize embedded array
                    rgbAtr = new byte[PCSCliteMacOsX.MAX_ATR_SIZE],
                    cbAtr  = PCSCliteMacOsX.MAX_ATR_SIZE
                };
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SCardReaderState"/> class.
 /// </summary>
 public SCardReaderState() {
     if (Platform.IsWindows) {
         _winscardRstate = new WINDOWS_SCARD_READERSTATE {
             // initialize embedded array
             rgbAtr = new byte[WinSCardAPI.MAX_ATR_SIZE],
             cbAtr = WinSCardAPI.MAX_ATR_SIZE
         };
     } else {
         _pcscliteRstate = new Interop.Unix.SCARD_READERSTATE {
             // initialize embedded array
             rgbAtr = new byte[PCSCliteAPI.MAX_ATR_SIZE],
             cbAtr = (IntPtr) PCSCliteAPI.MAX_ATR_SIZE
         };
     }
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SCardReaderState"/> class.
 /// </summary>
 public SCardReaderState()
 {
     if (Platform.IsWindows)
     {
         _winscardRstate = new WINDOWS_SCARD_READERSTATE {
             // initialize embedded array
             rgbAtr = new byte[WinSCardAPI.MAX_ATR_SIZE],
             cbAtr  = WinSCardAPI.MAX_ATR_SIZE
         };
     }
     else
     {
         _pcscliteRstate = new Interop.Unix.SCARD_READERSTATE {
             // initialize embedded array
             rgbAtr = new byte[PCSCliteAPI.MAX_ATR_SIZE],
             cbAtr  = (IntPtr)PCSCliteAPI.MAX_ATR_SIZE
         };
     }
 }
Beispiel #4
0
        public SCardError GetStatusChange(IntPtr hContext, IntPtr dwTimeout, SCardReaderState[] rgReaderStates)
        {
            SCARD_READERSTATE[] readerstates = null;
            var cReaders = 0;

            if (rgReaderStates != null)
            {
                // copy the last known state into the buffer
                cReaders     = rgReaderStates.Length;
                readerstates = new SCARD_READERSTATE[cReaders];
                for (var i = 0; i < cReaders; i++)
                {
                    readerstates[i] = rgReaderStates[i].WindowsReaderState;
                }
            }

            // On a 64-bit platforms .ToInt32() will throw an OverflowException
            var timeout = unchecked ((int)dwTimeout.ToInt64());
            var rc      = SCardHelper.ToSCardError(
                SCardGetStatusChange(
                    hContext,
                    timeout,
                    readerstates,
                    cReaders));

            if (rc != SCardError.Success || rgReaderStates == null)
            {
                return(rc);
            }

            for (var i = 0; i < cReaders; i++)
            {
                // replace with returned values
                rgReaderStates[i].WindowsReaderState = readerstates[i];
            }

            return(rc);
        }
Beispiel #5
0
        public SCardError GetStatusChange(IntPtr hContext, IntPtr dwTimeout, SCardReaderState[] rgReaderStates) {
            SCARD_READERSTATE[] readerstates = null;
            var cReaders = 0;

            if (rgReaderStates != null) {
                // copy the last known state into the buffer
                cReaders = rgReaderStates.Length;
                readerstates = new SCARD_READERSTATE[cReaders];
                for (var i = 0; i < cReaders; i++) {
                    readerstates[i] = rgReaderStates[i].WindowsReaderState;
                }
            }

            // On a 64-bit platforms .ToInt32() will throw an OverflowException 
            var timeout = unchecked((Int32) dwTimeout.ToInt64());
            var rc = SCardHelper.ToSCardError(
                SCardGetStatusChange(
                    hContext,
                    timeout,
                    readerstates,
                    cReaders));

            if (rc != SCardError.Success || rgReaderStates == null) {
                return rc;
            }

            for (var i = 0; i < cReaders; i++) {
                // replace with returned values
                rgReaderStates[i].WindowsReaderState = readerstates[i];
            }

            return rc;
        }