/// <inheritdoc /> public ErrorCode SCardListReaderGroups(IntPtr context, ref IntPtr groups, ref uint size) { ErrorCode err; unsafe { fixed(uint *psize = &size) { if (size == AutoAllocate) { char *pgroups; err = UnsafePrimitives.SCardListReaderGroups( (void *)context, (char *)&pgroups, psize ); var cgroups = new char[*psize]; fixed(char *pcgroups = cgroups) { for (var i = 0; i < *psize; i++) { pcgroups[i] = pgroups[i]; } UnsafePrimitives.SCardFreeMemory((void *)context, pgroups); groups = (IntPtr)pcgroups; } } else { err = UnsafePrimitives.SCardListReaderGroups( (void *)context, (char *)groups, psize ); } size = *psize; } } return(err); }
/// <inheritdoc /> public ErrorCode SCardListReaders(IntPtr context, string groups, ref IntPtr readers, ref uint size) { ErrorCode err; unsafe { fixed(uint *psize = &size) { fixed(char *pgroups = groups) { if (size == AutoAllocate) { char *preaders; err = UnsafePrimitives.SCardListReaders( (void *)context, pgroups, (char *)&preaders, psize ); if (err == ErrorCode.Success) { readers = UnsafePrimitives.CharPointerToIntPtr(preaders, *psize); UnsafePrimitives.SCardFreeMemory((void *)context, preaders); } } else { err = UnsafePrimitives.SCardListReaders( (void *)context, pgroups, (char *)readers, psize ); } size = *psize; } } } return(err); }
/// <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) { char *preaderName; byte *patr; ret = UnsafePrimitives.SCardStatus( (void *)card, (char *)&preaderName, preaderNameSize, &ustatus, &uprotocol, (byte *)&patr, patrSize ); if (ret == ErrorCode.Success) { readerName = UnsafePrimitives.CharPointerToIntPtr(preaderName, *preaderNameSize); UnsafePrimitives.SCardFreeMemory((void *)ActiveContext, preaderName); atr = UnsafePrimitives.BytePointerToIntPtr(patr, *patrSize); UnsafePrimitives.SCardFreeMemory((void *)ActiveContext, patr); } } else if (readerNameSize == AutoAllocate && atrSize != AutoAllocate) { char *preaderName; ret = UnsafePrimitives.SCardStatus( (void *)card, (char *)&preaderName, preaderNameSize, &ustatus, &uprotocol, (byte *)atr, patrSize ); if (ret == ErrorCode.Success) { readerName = UnsafePrimitives.CharPointerToIntPtr(preaderName, *preaderNameSize); UnsafePrimitives.SCardFreeMemory((void *)ActiveContext, preaderName); } } else if (readerNameSize != AutoAllocate && atrSize == AutoAllocate) { byte *patr; ret = UnsafePrimitives.SCardStatus( (void *)card, (char *)readerName, preaderNameSize, &ustatus, &uprotocol, (byte *)&patr, patrSize ); atr = UnsafePrimitives.BytePointerToIntPtr(patr, *patrSize); UnsafePrimitives.SCardFreeMemory((void *)ActiveContext, patr); } else { ret = UnsafePrimitives.SCardStatus( (void *)card, (char *)readerName, (uint *)readerNameSize, &ustatus, &uprotocol, (byte *)atr, (uint *)atrSize ); } status = (State)ustatus; protocol = (Protocol)uprotocol; readerNameSize = *preaderNameSize; atrSize = *patrSize; } } } return(ret); }