C# 调用delphi 写的dll 的问题,dll中包含结构体数组~~~~~~~~~~~
winform吧
全部回复
仅看楼主
level 1
脱凡羽 楼主
直接上代码,这个是dll 的源码
unit unitrecord;
interface
type tpumpings1 = record
time, proppant,
liquidrate,
liquidvolumea,
proppantmassa, fracturehalf,
fracturew: double;
end;
arrpump = array of tpumpings1;
arraystring = array of string;
function teststring(out data1:arrpump;out datastrv:variant): integer; stdcall;
exports
teststring;
implementation
function teststring(out data1:arrpump;out datastrv:variant): integer; stdcall;
var
i: integer;
datastr: arraystring;
begin
result := 0;
setlength(data1, 5);
for i := 0 to 4 do
begin
data1[i].time := (i + 1) * 10;
data1[i].proppant := (i + 1) * 9;
data1[i].liquidrate := (i + 1) * 8;
data1[i].liquidvolumea := (i + 1) * 7;
data1[i].proppantmassa := (i + 1) * 6;
data1[i].fracturehalf := (i + 1) * 5;
data1[i].fracturew := (i + 1) * 4;
end;
setlength(datastr, 2);
datastr[0] := '传奇';
datastr[1] := '楚汉';
datastrv := datastr;
result := 1;
end;
end.
这是我在C# 一个窗体中的代码
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Collections;
namespace ttttt
{
public partial class Form1 : Form
{
[DllImport("recordtest.dll")]
public static extern int teststring(out tpumpings1[,] data1, out object datastrv);
public Form1()
{
InitializeComponent();
}
public struct tpumpings1
{
public double time;
public double proppant;
public double liquidrate;
public double liquidvolumea;
public double proppantmassa;
public double fracturehalf;
public double fracturew;
}
private void buttonClick_Click(object sender, EventArgs e)
{
tpumpings1[,] data1;
object aa;
if (teststring(out data1, out aa) == 1)
{
MessageBox.Show(data1.Length.ToString());
}
}
}
}
按理说弹出data1 的长度应该是5 的,可是运行效果是1,到底是怎么回事?dll写的不对还是C# 调用代码写的不对?
2013年01月24日 01点01分 1
level 1
脱凡羽 楼主
自己顶!!!!!!!!!!!!!!
2013年01月24日 01点01分 2
level 1
脱凡羽 楼主
在线等高手!!!!!!!!!!!!!!!
2013年01月24日 01点01分 3
level 2
自己找c#和delphi对应数据类型
2015年05月16日 13点05分 4
level 3
2015年05月28日 09点05分 5
1