Example #1
0
        public void sCardEstablishContext(out string status)
        {
            status = "";

            try
            {
                dwscope = 2;
                if (readerName != "" && readerName != null)
                {
                    retval = HID.SCardEstablishContext(dwscope, IntPtr.Zero, IntPtr.Zero, out hContext);
                    if (retval == 0)
                    {
                        IsAuthenticated = false;
                        status          = "> SCardEstablishContext" + " Successful";
                        release_flag    = true;
                    }
                    else
                    {
                        status = "> SCardEstablishContext" + " Failed... " + " Error Code: " + String.Format("{0:x}", retval) + "H\n";
                        //timer.Enabled = false;
                    }
                }
                else
                {
                    status = "Failed... " + String.Format("{0:x}", retval) + "H\n";
                    //timer.Enabled = false;
                }
            }
            catch { }
        }
Example #2
0
        public List <string> getListReaders()
        {
            uint pcchReaders = 0;
            int  nullindex   = -1;
            char nullchar    = (char)0;

            dwscope = 2;

            // Establish context.
            retval = HID.SCardEstablishContext(dwscope, IntPtr.Zero, IntPtr.Zero, out hContext);
            if (retval != 0)
            {
                throw new Exception("Błąd wykonania polecenia HID.SCardEstablishContext");
            }
            retval = HID.SCardListReaders(hContext, null, null, ref pcchReaders);
            byte[] mszReaders = new byte[pcchReaders];

            // Fill readers buffer with second call.
            retval = HID.SCardListReaders(hContext, null, mszReaders, ref pcchReaders);

            // Populate List with readers.
            string currbuff = Encoding.ASCII.GetString(mszReaders);

            ReaderList = currbuff;

            int len = (int)pcchReaders;

            if (len > 0)
            {
                while (currbuff[0] != nullchar)
                {
                    nullindex = currbuff.IndexOf(nullchar);   // Get null end character.
                    string reader = currbuff.Substring(0, nullindex);
                    readers.Add(reader);
                    len      = len - (reader.Length + 1);
                    currbuff = currbuff.Substring(nullindex + 1, len);
                }
            }
            return(readers);
        }