在以下动态库的一个函数声明中
[DllImport("Mwic_32.dll", EntryPoint="swr_4442", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 向指定地址写数据
//调用: icdev: 通讯设备标识符 offset: 偏移地址,其值范围0~255
// len: 字符串长度,其值范围1~256 w_string: 写入数据 [MarshalAs(UnmanagedType.LPArray)] byte[] StringBuilder
//返回: <0 错误 =0 正确
public static extern Int16 swr_4442(int icdev, Int16 offset, Int16 len, [MarshalAs(UnmanagedType.LPArray)]byte[] w_string);
[MarshalAs(UnmanagedType.LPArray)]byte[] w_string 这句话中MarshalAs和UnmanagedType..LPArray的作用是什么?
------解决思路----------------------
这是让这个参数以C风格数组方式传递,这里就相当于传递了那个字节数组的起始地址。没记错的话不写这个默认也应该是这个方式。