这是在调用Char*类型的指针存储数据时候出现的问题;
要调用的函数申明如下:
int ReadBaseMsgPhoto(char* pMsg, int * len, char* directory);
C++中:pMsg为需要传入的char类型数组;
len 为指针;
directory 为需要传入的char类型数组;
网上找了下,方法很多,提供其中一种:
1.由于需要不少于198个字节的数据,所以申请了256个字节大小的数组,
并使用byte保存,即用byte类型的数组申明一个byte类型的数组,
用ref 对指针变量进行引用
1.导入dll函数:
[DllImport("Sdtapi.dll")]
public static extern int ReadBaseMsgPhoto(ref byte pMsg, ref int len, string directory);
2.
byte[] pMsg = new byte[256];
int len = 0;
string directory = "PicPath";
//如下传参即可
ReadBaseMsgPhoto(ref pMsg[0],ref len,directory);
总结:
1.如果需要大空间的就需要自己提前申请内存,如果只是传入数据,可以用string类型的数据传参;