From 6ad753a9794fc96e97d098c40a244507ea557aef Mon Sep 17 00:00:00 2001 From: David Hall Date: Sun, 28 May 2023 15:41:08 -0600 Subject: [PATCH] Update WinSCard.cs with nullable support and UIntPtr --- PInvoke/WinSCard/WinSCard.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/PInvoke/WinSCard/WinSCard.cs b/PInvoke/WinSCard/WinSCard.cs index 6e007a7c..eea64615 100644 --- a/PInvoke/WinSCard/WinSCard.cs +++ b/PInvoke/WinSCard/WinSCard.cs @@ -1,8 +1,9 @@ +#nullable enable global using System; global using System.Runtime.InteropServices; global using Vanara.InteropServices; -global using SCARDCONTEXT = nuint; +global using SCARDCONTEXT = UIntPtr; using System.Linq; using System.Text; using Vanara.Extensions; @@ -1676,7 +1677,7 @@ public static partial class WinSCard /// /// /// - /// The icon should be 256 × 256 pixels with no alpha channel. + /// The icon should be 256 × 256 pixels with no alpha channel. /// Examples /// /// PBYTE pbIcon = NULL; DWORD cbIcon = SCARD_AUTOALLOCATE; DWORD i; LONG lReturn; LPTSTR szReaderName = "USB Smart Card Reader 0"; // Retrieve the reader's icon. // hContext was set by a previous call to SCardEstablishContext. lReturn = SCardGetReaderIcon(hContext, szReaderName, (PBYTE)&pbIcon, &cbIcon); if ( SCARD_S_SUCCESS != lReturn ) { printf("Failed SCardGetReaderIcon - %x\n", lReturn); // Take appropriate action. } else { // Free the memory when done. lReturn = SCardFreeMemory(hContext, pbIcon); } @@ -2910,7 +2911,7 @@ public static partial class WinSCard /// /// Examples /// - /// szDeviceInstanceIdcchReaderNameLONG lReturn, lReturn2; LPTSTR pmszReaders = NULL; LPTSTR pReader = NULL;WCHAR DWORD cchReaderName = SCARD_AUTOALLOCATE; // Retrieve the reader’s name from it’s device instance ID // hContext was set by a previous call to SCardEstablishContext. // szDeviceInstanceId was obtained by calling SetupDiGetDeviceInstanceId lReturn = SCardListReadersWithDeviceInstanceId (hContext, szDeviceInstanceId, (LPTSTR)&pmszReaders, &cchReaderName); switch( lReturn ) { case SCARD_E_NO_READERS_AVAILABLE: printf("No readers have the provided device instance ID.\n"); // Take appropriate action. // ... break; case SCARD_S_SUCCESS: // Do something with the multi string of readers. // Output the values. // A double-null terminates the list of values. pReader = pmszReaders; while ( '\0' != *pReader ) { // Display the value. printf("Reader: %S\n", pReader ); // Advance to the next value. pReader = pReader + wcslen((wchar_t *)pReader) + 1; } // Free the memory. lReturn2 = SCardFreeMemory( hContext, pmszReaders ); if ( SCARD_S_SUCCESS != lReturn2 ) printf("Failed SCardFreeMemory\n"); break; default: printf("Failed SCardListReaders\n"); // Take appropriate action. // ... break; + /// szDeviceInstanceIdcchReaderNameLONG lReturn, lReturn2; LPTSTR pmszReaders = NULL; LPTSTR pReader = NULL;WCHAR DWORD cchReaderName = SCARD_AUTOALLOCATE; // Retrieve the readerÂ’s name from itÂ’s device instance ID // hContext was set by a previous call to SCardEstablishContext. // szDeviceInstanceId was obtained by calling SetupDiGetDeviceInstanceId lReturn = SCardListReadersWithDeviceInstanceId (hContext, szDeviceInstanceId, (LPTSTR)&pmszReaders, &cchReaderName); switch( lReturn ) { case SCARD_E_NO_READERS_AVAILABLE: printf("No readers have the provided device instance ID.\n"); // Take appropriate action. // ... break; case SCARD_S_SUCCESS: // Do something with the multi string of readers. // Output the values. // A double-null terminates the list of values. pReader = pmszReaders; while ( '\0' != *pReader ) { // Display the value. printf("Reader: %S\n", pReader ); // Advance to the next value. pReader = pReader + wcslen((wchar_t *)pReader) + 1; } // Free the memory. lReturn2 = SCardFreeMemory( hContext, pmszReaders ); if ( SCARD_S_SUCCESS != lReturn2 ) printf("Failed SCardFreeMemory\n"); break; default: printf("Failed SCardListReaders\n"); // Take appropriate action. // ... break; /// /// /// Note @@ -4208,7 +4209,7 @@ public static partial class WinSCard /// /// A handle to an icon (32 x 32 pixels). You can specify a vendor-specific icon to display in the dialog box. If this value is - /// NULL, a generic, smart card reader–loaded icon is displayed. + /// NULL, a generic, smart card reader–loaded icon is displayed. /// public HICON hIcon;