How can i skip the optional parameter (pioRecvPci) in C#? I think the main problem is that in C the parameter is a pointer so it is possible to supply NULL while in C# the ref keyword on a struct is used which can't be null by definition.
C Code
typedef struct {
DWORD dwProtocol;
DWORD cbPciLength;
} SCARD_IO_REQUEST;
LONG WINAPI SCardTransmit(
__in SCARDHANDLE hCard,
__in LPCSCARD_IO_REQUEST pioSendPci,
__in LPCBYTE pbSendBuffer,
__in DWORD cbSendLength,
__inout_opt LPSCARD_IO_REQUEST pioRecvPci,
__out LPBYTE pbRecvBuffer,
__inout LPDWORD pcbRecvLength
);
C# Code
[StructLayout(LayoutKind.Sequential)]
public struct SCARD_IO_REQUEST
{
public int dwProtocol;
public int cbPciLength;
}
[DllImport("winscard.dll")]
public static extern int SCardTransmit(
int hCard,
ref SCARD_IO_REQUEST pioSendRequest,
ref byte SendBuff,
int SendBuffLen,
ref SCARD_IO_REQUEST pioRecvRequest,
ref byte RecvBuff,
ref int RecvBuffLen);
You can change the
structto aclassand then passnull. Remember that a C#structis quite different from a C++struct, and here your really want to use a C#class.Or if you always want to ignore
pioRecvRequestchange the signature ofSCardTransmitso thatpioRecvRequestis of typeIntPtr. Then passIntPtr.Zerofor the value.Actually, the
SCARD_IO_REQUESTis just a header and if you want to pass it in the call you will have to manage this structure and the additional buffer space yourself anyway soIntPtris the right choice. You will then have to use theMarshalfunctions to allocate and fill the structure before the call and unmarshal the data and free it after the call.