c++代码:
class qf
{
private:
char *id;
char *mc;
float sd;
int LX;
};
函数:int EntryPoint(qf *qfw);
c#代码:
public class qf
{
private string id;
private string mc;
private float sd;
private int LX;
};
c#调用:
qf[] qfw = new qf[2];
for (int i = 0; i < qfw.Length; i++)
{
qfw[i] = new qf(t, t, (float)0.5, 1);
}
IntPtr[] ptrarr = new IntPtr[1];
ptrarr[0] = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(qf)) * 2); //分配包含两个元素的数组
IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(qf)));
Marshal.Copy(ptrarr, 0, pt, 1); //拷贝指针数组
dll.EntryPoint( pt);
可以进入c++,但是传进去的pt是乱码?这是为何呢?求大神解释?