/// <summary> /// Wraps the PCSC function /// LONG SCardEndTransaction( /// SCARDHANDLE hCard, /// DWORD dwDisposition /// ); /// </summary> /// <param name="Disposition">A value from DISCONNECT enum</param> public override void EndTransaction(DISCONNECT Disposition) { if (PCSC.SCardIsValidContext(context) == PCSC.SCARD_S_SUCCESS) { lastError = PCSC.SCardEndTransaction(cardHandle, (UInt32)Disposition); ThrowSmartcardException("SCardEndTransaction", lastError); } }
/// <summary> /// Wraps the PSCS function /// LONG SCardBeginTransaction( /// SCARDHANDLE hCard // ); /// </summary> public override void BeginTransaction() { if (PCSC.SCardIsValidContext(context) == PCSC.SCARD_S_SUCCESS) { lastError = PCSC.SCardBeginTransaction(cardHandle); ThrowSmartcardException("SCardBeginTransaction", lastError); } }
/// <summary> /// Wraps the PCSC function /// LONG SCardReleaseContext( /// IN SCARDCONTEXT hContext /// ); /// </summary> public void ReleaseContext() { if (PCSC.SCardIsValidContext(context) == PCSC.SCARD_S_SUCCESS) { lastError = PCSC.SCardReleaseContext(context); ThrowSmartcardException("SCardReleaseContext", lastError); context = IntPtr.Zero; } }
/// <summary> /// Wraps the PCSC function /// LONG SCardReleaseContext( /// IN SCARDCONTEXT hContext /// ); /// </summary> private static void ReleaseContext(IntPtr hContext) { if (PCSC.SCardIsValidContext(hContext) == PCSC.SCARD_S_SUCCESS) { int lastError = PCSC.SCardReleaseContext(hContext); ThrowSmartcardException("SCardReleaseContext", lastError); //Marshal.FreeHGlobal(hContext); hContext = IntPtr.Zero; } }
/// <summary> /// Wraps the PCSC function /// LONG SCardDisconnect( /// IN SCARDHANDLE hCard, /// IN DWORD dwDisposition /// ); /// </summary> /// <param name="Disposition"></param> public override void Disconnect(DISCONNECT Disposition) { if (PCSC.SCardIsValidContext(context) == PCSC.SCARD_S_SUCCESS) { lastError = PCSC.SCardDisconnect(cardHandle, (uint)Disposition); cardHandle = IntPtr.Zero; try { ThrowSmartcardException("SCardDisconnect", lastError); } finally { ReleaseContext(); } } }