You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to invoke SCardTransmit with the code below and getting an exception with the message "Cannot marshal 'parameter #2': Generic types cannot be marshaled.".
Looking at how other functions that also take a SafeCoTaskMemStruct are declared, it seems like the problem is exactly what the exception message says: the parameters have to be declared as IntPtr
public bool SendCommand(byte[] data, out byte[] output)
{
var sendPci = new WinSCard.SCARD_IO_REQUEST();
sendPci.dwProtocol = _activeProtocol;
sendPci.cbPciLength = (uint)Marshal.SizeOf(sendPci);
var recvPci = new WinSCard.SCARD_IO_REQUEST();
recvPci.dwProtocol = _activeProtocol;
recvPci.cbPciLength = (uint)Marshal.SizeOf(recvPci);
uint recvLength = 256;
output = new byte[recvLength];
GCHandle dataPinned = GCHandle.Alloc(data, GCHandleType.Pinned);
GCHandle recvDataPinned = GCHandle.Alloc(output, GCHandleType.Pinned);
var _lastRet = WinSCard.SCardTransmit(_card,
new SafeCoTaskMemStruct<WinSCard.SCARD_IO_REQUEST>(sendPci),
dataPinned.AddrOfPinnedObject(),
(uint)data.Length,
new SafeCoTaskMemStruct<WinSCard.SCARD_IO_REQUEST>(recvPci),
recvDataPinned.AddrOfPinnedObject(),
ref recvLength);
dataPinned.Free();
recvDataPinned.Free();
return _lastRet.Succeeded;
}
The text was updated successfully, but these errors were encountered:
I'm trying to invoke SCardTransmit with the code below and getting an exception with the message "Cannot marshal 'parameter #2': Generic types cannot be marshaled.".
Looking at how other functions that also take a SafeCoTaskMemStruct are declared, it seems like the problem is exactly what the exception message says: the parameters have to be declared as IntPtr
The text was updated successfully, but these errors were encountered: