public Readers(ReaderScope scope) { uint retVal; switch (scope) { case ReaderScope.Null: context = new CardContextSafeHandler(IntPtr.Zero); break; case ReaderScope.System: retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_SYSTEM, IntPtr.Zero, IntPtr.Zero, out context); if (retVal != 0) { throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X")); } break; case ReaderScope.User: retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_USER, IntPtr.Zero, IntPtr.Zero, out context); if (retVal != 0) { throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X")); } break; } List = new List <string>(); UpdateList(); }
public Readers(ReaderScope scope) { uint retVal; switch (scope) { case ReaderScope.Null: context = new CardContextSafeHandler(IntPtr.Zero); break; case ReaderScope.System: retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_SYSTEM, IntPtr.Zero, IntPtr.Zero, out context); if (retVal != 0) { throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X")); } break; case ReaderScope.User: retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_USER, IntPtr.Zero, IntPtr.Zero, out context); if (retVal != 0) { throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X")); } break; } int size = 0; //List the readers //todo::listen for new readers changes (via the "\\?PnP?\Notification" reader) char[] readers = null; retVal = NativeMethods.SCardListReaders(context, null, readers, ref size); if (retVal != 0 && retVal != 0x8010002E) { throw new InvalidOperationException("Failed to list readers (length): 0x" + retVal.ToString("X")); } if (retVal == 0x8010002E) //no readers { List = new List <string>(0); } else { readers = new char[size]; retVal = NativeMethods.SCardListReaders(context, null, readers, ref size); if (retVal != 0) { throw new InvalidOperationException("Failed to list readers: 0x" + retVal.ToString("X")); } List = MultiString.ToStringList(readers); } }
internal EidCard(CardContextSafeHandler context, String readerName) { this.context = context; this.ReaderName = readerName; CardProtocols protocol; uint retVal = NativeMethods.SCardConnect(context, ReaderName, CardShareMode.SCARD_SHARE_SHARED, CardProtocols.SCARD_PROTOCOL_T0 | CardProtocols.SCARD_PROTOCOL_T1, out handler, out protocol); if (retVal == 0x80100069L) throw new NoCardException("Not card was found in the reader"); if (retVal == 0x8010000BL) throw new ReaderException("The card is being accessed from a different context"); if (retVal == 0x80100009L) throw new ReaderException("The specified reader does not exist"); if (retVal != 0) throw new InvalidOperationException("Failed to open card reader: 0x" + retVal.ToString("X")); }
public Readers(ReaderScope scope) { uint retVal; switch (scope) { case ReaderScope.Null: context = new CardContextSafeHandler(IntPtr.Zero); break; case ReaderScope.System: retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_SYSTEM, IntPtr.Zero, IntPtr.Zero, out context); if (retVal != 0) throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X")); break; case ReaderScope.User: retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_USER, IntPtr.Zero, IntPtr.Zero, out context); if (retVal != 0) throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X")); break; } }
internal static extern uint SCardConnect(CardContextSafeHandler hContext, String szReader, CardShareMode dwShareMode, CardProtocols dwPreferredProtocols, out CardSafeHandler phCard, out CardProtocols pdwActiveProtocol);
internal static extern uint SCardFreeMemory(CardContextSafeHandler hContext, IntPtr pvMem);
internal Card(CardContextSafeHandler context, String readerName, byte[] atr) { this.context = context; this.ReaderName = readerName; this.ATR = atr; }
internal static extern uint SCardGetStatusChange(CardContextSafeHandler hContext, int dwTimeout, [In, Out] SCARD_READERSTATE[] rgReaderStates, int cReaders);
internal static extern uint SCardLocateCards(CardContextSafeHandler hContext, [In, MarshalAs(UnmanagedType.LPArray)] Char[] mszCards, [In, Out] SCARD_READERSTATE[] rgReaderStates, int cReaders);
internal static extern uint SCardListCards(CardContextSafeHandler hContext, byte[] pbAtr, IntPtr rgguidInterfaces, int cguidInterfaceCount, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)] Char[] mszCards, [In, Out] ref int pcchCards);
internal static extern uint SCardEstablishContext([MarshalAs(UnmanagedType.U4)] ContextScope dwScope, IntPtr pvReserved1, IntPtr pvReserved2, out CardContextSafeHandler phContext);
internal static extern uint SCardListReaders(CardContextSafeHandler hContext, [In, MarshalAs(UnmanagedType.LPArray)] Char[] mszGroups, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] Char[] mszReaders, [In, Out] ref int pcchReaders);
internal EidCard(CardContextSafeHandler context, String readerName, byte[] atr) : base(context, readerName, atr) { }