/// <inheritdoc /> public ErrorCode SCardStatus(IntPtr card, ref State status, ref Protocol protocol) { ErrorCode ret; unsafe { var ustatus = (uint)status; var uprotocol = (uint)protocol; uint readerNameSize = 0; uint atrSize = 0; ret = UnsafePrimitives.SCardStatus((void *)card, null, &readerNameSize, &ustatus, &uprotocol, null, &atrSize); status = (State)ustatus; protocol = (Protocol)uprotocol; } return(ret); }
/// <inheritdoc /> public ErrorCode SCardStatus(IntPtr card, ref IntPtr readerName, ref uint readerNameSize, ref State status, ref Protocol protocol, ref IntPtr atr, ref uint atrSize) { ErrorCode ret; unsafe { var ustatus = (uint)status; var uprotocol = (uint)protocol; fixed(uint *preaderNameSize = &readerNameSize) { fixed(uint *patrSize = &atrSize) { if (readerNameSize != AutoAllocate && atrSize != AutoAllocate) { ret = UnsafePrimitives.SCardStatus( (void *)card, (char *)readerName, (uint *)readerNameSize, &ustatus, &uprotocol, (byte *)atr, (uint *)atrSize ); } else { //TODO throw new NotImplementedException(); } status = (State)ustatus; protocol = (Protocol)uprotocol; readerNameSize = *preaderNameSize; atrSize = *patrSize; } } } return(ret); }
/// <inheritdoc /> public ErrorCode SCardStatus(IntPtr card, ref string readerName, ref State state, ref Protocol protocol, ref byte[] atr) { var atrPtr = IntPtr.Zero; var zReaderNameSize = AutoAllocate; var zReaderNamePtr = new IntPtr(); var atrSize = AutoAllocate; var ret = UnsafePrimitives.SCardStatus( card, ref zReaderNamePtr, ref zReaderNameSize, ref state, ref protocol, ref atrPtr, ref atrSize ); if (zReaderNamePtr == IntPtr.Zero) { readerName = ""; } else { var readerStr = Marshal.PtrToStringAuto(zReaderNamePtr, (int)zReaderNameSize - 2); readerName = readerStr.Split('\0')[0]; } if (atrPtr == IntPtr.Zero) { atr = new byte[0]; } else { atr = new byte[atrSize]; Marshal.Copy(atrPtr, atr, 0, (int)atrSize); } return(ret); }