C#.net 调用Dll 参数传递问题
[DllImport("k8110.dll")]
static extern bool CAN_Init(long iIndex, ref Byte[] config);//把他转到C#
//Public Declare Function CAN_Init Lib "k8110.dll" (ByVal iIndex As Long, ByRef config As Any) As Boolean /这个是vb 的代码
Byte[] Conf = new Byte[5];
Conf[0] = 1;
Conf[1] = 2;
Conf[2] = 3;
Conf[3] = 4;
Conf[4] = 5;
OpenReturn = CAN_Init(0, ref Conf);//get a Error
//Attempted to read or write protected memory. This is often an indication that other memory is corrupt.咋整!
[DllImport("k8110.dll")]
static extern bool CAN_Init(long iIndex, ref Byte[] config);//把他转到C#
//Public Declare Function CAN_Init Lib "k8110.dll" (ByVal iIndex As Long, ByRef config As Any) As Boolean /这个是vb 的代码
Byte[] Conf = new Byte[5];
Conf[0] = 1;
Conf[1] = 2;
Conf[2] = 3;
Conf[3] = 4;
Conf[4] = 5;
OpenReturn = CAN_Init(0, ref Conf);//get a Error
//Attempted to read or write protected memory. This is often an indication that other memory is corrupt.咋整!
OpenReturn = CAN_Init(0, Conf)这样应该就可以了。
static extern int CAN_Init(int iIndex, [MarshalAs(UnmanagedType.LPArray)]Byte[] config);好多类型都错了,数组和string绝对不能ref传递给API