我用C#调用Delphi写的dll,遇到以下问题:Delphi接口函数function W_information(var info:integer):integer;info是数组首地址function W_flag(var f:boolean):integer;f是数组首地址C#调用声明[DllImport("D.dll")]static int32 W_information(ref int32 info):integer;[DllImport("D.dll")]static int32 W_flag(ref bool f):integer; private write_onclick(){ int32[] info=new int32[3]; info[0]=1; info[1]=2; info[2]=3; W_information(ref info[0]); bool[] f=new bool[2]; f[0]=false; f[1]=true; W_flag(ref f[0]);}W_information操作的结果是正确的,但W_flag操作的结果是错误的。我之前以为是f数组的地址不连续导致,但我查过资料,数组的地址都是连续的。
然后调用时,f定义为int32[] f = new int32[8](真假分别用0和1表示),这样调用,就不会出现错误,为什么呢?
Delphi接口函数function W_information(var info:integer):integer;info是数组首地址function W_flag(var f:boolean):integer;f是数组首地址C#调用声明[DllImport("D.dll")]static int32 W_information(ref int32 info):integer;[DllImport("D.dll")]static int32 W_flag(ref byte f):integer; private write_onclick(){ int32[] info=new int32[3]; info[0]=1; info[1]=2; info[2]=3; W_information(ref info[0]); byte[] f=new byte[2]; f[0]=Convert.ToByte(false); f[1]=Convert.ToByte(true); W_flag(ref f[0]);}
问题解决