C#调用C++接口时参数传递问题,比如 c++接口:
1:
long __stdcall SD_GetInputPass(long ReaderHandle, unsigned char ctime, unsigned char* rlen, unsigned char* cpass)
2:
long __stdcall SD_VerifyPin(long ReaderHandle, unsigned char *PIN, short *Sw1Sw2)
3:
int BankTrans(char* InputData, char* OutPutData)
等等类型,在C#中调用时应该如何传递参数?最好能整体说一下原理,拜谢各位大佬。我补充下我调用第一个接口的错误代码,这个代码调用没问题,硬件设备已经执行,只是返回结果时报错,
[DllImport(@"C:\LD_APOSA8\MisPos.dll")]
public static extern long SD_GetInputPass(long ReaderHandle, string ctime, byte[] rlen, byte[] cpass);
long ReaderHandle = long.Parse("03");
string ctime = "01";
byte[] rlen = new byte[10];
byte[] cpass = new byte[20];
SD_GetInputPass(ReaderHandle, ctime, rlen, cpass);
再补充一下,以下两种对照方式我都试过了:
//c++:unsigned char * <==> c#:ref byte
//c++:unsigned char * <==> c#:[MarshalAs(UnmanagedType.LPArray)] byte[]