예제 #1
0
        public SCardError Connect(
            IntPtr hContext,
            string szReader,
            SCardShareMode dwShareMode,
            SCardProtocol dwPreferredProtocols,
            out IntPtr phCard,
            out SCardProtocol pdwActiveProtocol)
        {
            byte[] readername = SCardHelper._ConvertToByteArray(szReader, textEncoding, SCardAPI.Lib.CharSize);
            Int32  sharemode  = (Int32)dwShareMode;
            Int32  prefproto  = (Int32)dwPreferredProtocols;
            IntPtr ctx        = (IntPtr)hContext;
            IntPtr card;
            Int32  activeproto;

            Int32 result = SCardConnect(ctx,
                                        readername,
                                        sharemode,
                                        prefproto,
                                        out card,
                                        out activeproto);

            phCard            = card;
            pdwActiveProtocol = (SCardProtocol)activeproto;

            return(SCardHelper.ToSCardError(result));
        }
예제 #2
0
        public SCardError ListReaders(
            IntPtr hContext,
            string[] Groups,
            out string[] Readers)
        {
            IntPtr     ctx       = (IntPtr)hContext;
            Int32      dwReaders = 0;
            SCardError rc;

            // initialize groups array
            byte[] mszGroups = null;
            if (Groups != null)
            {
                mszGroups = SCardHelper._ConvertToByteArray(Groups, textEncoding);
            }

            // determine the needed buffer size
            rc = SCardHelper.ToSCardError(
                SCardListReaders(ctx,
                                 mszGroups,
                                 null,
                                 ref dwReaders));

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

            // initialize array
            byte[] mszReaders = new byte[(int)dwReaders * sizeof(char)];

            rc = SCardHelper.ToSCardError(
                SCardListReaders(ctx,
                                 mszGroups,
                                 mszReaders,
                                 ref dwReaders));

            if (rc == SCardError.Success)
            {
                Readers = SCardHelper._ConvertToStringArray(mszReaders, textEncoding);
            }
            else
            {
                Readers = null;
            }

            return(rc);
        }