小弟是菜鸟, 在 调用 c++的dll 的出了一个问题。
c++ dll的函数为 int GetIDList(HANDLE khandle,char IDList[][20] , int &IDNum)
我封装的c#函数为 public static extern int GetIDList(IntPtr khandle, char[][] IDList, ref int IDNum);
我声明了一个数组 public char[][] ID_st;
ID_st = new char[10000][];
for (int i = 0; i < 10000;i++ )
{
ID_st[i]=new char[20];
}
但是在调用该函数后发生异常 ,说 运行的时候出异常了 无法封送处理“parameter #2”: 嵌套的数组不支持封送处理 然后我换一种封装方式 public static extern int GetIDList(IntPtr khandle, string[] IDList, ref int IDNum);
string [] ID_st =new string[10000];
然后在调用函数后 ,可以运行 但是 string 数组中 都还是空的,没有得到赋值,各个高手 帮我看看 ,该怎样封装啊。
c++ dll的函数为 int GetIDList(HANDLE khandle,char IDList[][20] , int &IDNum)
我封装的c#函数为 public static extern int GetIDList(IntPtr khandle, char[][] IDList, ref int IDNum);
我声明了一个数组 public char[][] ID_st;
ID_st = new char[10000][];
for (int i = 0; i < 10000;i++ )
{
ID_st[i]=new char[20];
}
但是在调用该函数后发生异常 ,说 运行的时候出异常了 无法封送处理“parameter #2”: 嵌套的数组不支持封送处理 然后我换一种封装方式 public static extern int GetIDList(IntPtr khandle, string[] IDList, ref int IDNum);
string [] ID_st =new string[10000];
然后在调用函数后 ,可以运行 但是 string 数组中 都还是空的,没有得到赋值,各个高手 帮我看看 ,该怎样封装啊。
试试这样
public static extern int GetIDList(IntPtr khandle, IntPtr IDList, ref int IDNum);//..........
byte [] Buffer=new Byte[4096];unsafe{
fixed(byte* pb=&Buffer[0]){
IntPtr p=(IntPtr)pb;
GetIDList(kHandle,p,ref IDNum); }
}
然后再 Buffer里面,每20个字节是一段
http://blog.csdn.net/Mittermeyer/archive/2007/04/27/1586867.aspx建议申明1维数组,返回的数据然后自己处理,例如包装个类,定义个方法,按照[][]的形式访问。
大哥 我第二种封装方式下,ID_st 是调用c++的dll来赋值的,关键就是c++的dll没有给我赋值成功啊?!
或
public byte* name=Statalloc byte[100];
要想返回值参数是不是得声明为ref
string [] ID_st =new string[10000];
public static extern int GetIDList(IntPtr khandle, ref string[] IDList, ref int IDNum);
2,将C#的声明改成public static extern int GetIDList(IntPtr khandle, object IDList, ref int IDNum);
3,在c#中声明一个char[][]型的数组,赋好值,传入函数试试.