请教:c# 平台调用复杂结构体 非托管 DLL
c中的定义:typedef struct _test
{
int* a;
int size1;
int size2;
}test;
c#中定义:
public class test
{
[MarshalAs(UnmanagedType.ByValArray/*, SizeConst = IMAGE_SIZE*/)]
public int[] a;
[MarshalAs(UnmanagedType.I4)]
public int size1;
[MarshalAs(UnmanagedType.I4)]
public int size2;
}
private static void ss()
{
test t = new test();
t.a = new int[IMAGE_SIZE];
for (int i = 0; i < IMAGE_SIZE; i++)
t.a[i] =i;
t.size1 = 3;
t.size2 = 5;
testfun(t);
//IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(t));
//Marshal.StructureToPtr(t, ptr, true);
//testfun(ptr);
//test tt =(test)Marshal.PtrToStructure(ptr, typeof(test));
//MessageBox.Show(tt.a[0].ToString());
//MessageBox.Show(tt.b);
//Marshal.FreeHGlobal(ptr);
}
不知那里出了问题,传值一直有问题,数组可以传递,但是两个整形则传不过去,是一个很大的整数。请问问题出在那里?