예제 #1
0
        public SCardError Connect(IntPtr hContext, string szReader, SCardShareMode dwShareMode, SCardProtocol dwPreferredProtocols, out IntPtr phCard, out SCardProtocol pdwActiveProtocol)
        {
            var readername = SCardHelper.ConvertToByteArray(szReader, TextEncoding, Platform.Lib.CharSize);

            var result = SCardConnect(hContext,
                                      readername,
                                      (int)dwShareMode,
                                      (int)dwPreferredProtocols,
                                      out phCard,
                                      out var activeproto);

            pdwActiveProtocol = (SCardProtocol)activeproto;

            return(SCardHelper.ToSCardError(result));
        }
        public SCardError ListReaders(IntPtr hContext, string[] groups, out string[] readers)
        {
            var dwReaders = 0;

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

            // determine the needed buffer size

            var ctx = hContext.ToInt32();
            var rc  = SCardHelper.ToSCardError(
                MacOsxNativeMethods.SCardListReaders(
                    ctx,
                    mszGroups,
                    null,
                    ref dwReaders));

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

            // initialize array for returning reader names
            var mszReaders = new byte[(int)dwReaders];

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

            readers = (rc == SCardError.Success)
                ? SCardHelper.ConvertToStringArray(mszReaders, TextEncoding)
                : null;

            return(rc);
        }
예제 #3
0
        public SCardError ListReaders(IntPtr hContext, string[] groups, out string[] readers)
        {
            var dwReaders = 0;

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

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

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

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

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

            readers = (rc == SCardError.Success)
                ? SCardHelper.ConvertToStringArray(mszReaders, TextEncoding)
                : null;

            return(rc);
        }