c#调用Delphi DLL参数为结构体数组
Delphi结构体如下PICRecord=^TICRecord;TICRecord=packedrecordCard:array[0..19]ofchar;timeStr...
Delphi结构体如下
PICRecord=^TICRecord;
TICRecord=packed record
Card: array[0..19] of char;
timeString: array[0..19] of char;
EmpId: array[0..9] of char;
mark: Integer;
flag: Integer;
cardTimes: Integer;
end;
Delphi相关DLL函数
function AddData(var A:integer;var Records:array of TICRecord):integer; stdcall;
var
i ,Count :integer;
begin
Count:=16;
for i:=0 to Count do
begin
Records[i].Card:='1789456456';
end;
result:=A;
end;
exports AddData;
C#结构体如下
public struct TICRecord
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 21)]
public string Card; // 卡号字符串
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 21)]
public string TimeString; // 14位刷卡时间字符串, 格式为yyyymmddhhnnss
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
public string EmpID;
public Int32 Mark; // 读卡机标识字符
public Int32 Flag; // 存储卡的结果
public Int32 CardTimes; // 发卡次数, 0-15
}
C#调用方法
[DllImport("Test.dll", EntryPoint = "AddData", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern Int32 AddData(ref Int32 A,[In,Out] TICRecord[] B, Int32 Records_Size);
TICRecord[] TICRecordList = new TICRecord[Records_Size];
int Result = DongBao.AddData(ref a, TICRecordList, Records_Size);
MessageBox.Show( "返回值:"+Result+ "");
string Str = "";
for (int i = 0; i < Records_Size; i++)
{
Str += i + " ";
Str += Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(TICRecordList[i].Card)) + "\r\n";
}
MessageBox.Show("如果成功则返回100:现在返回的是" + Str + "");
返回结果,只有第一条有记录,其他的都为空,求处理过相关问题的老师指导一下 展开
PICRecord=^TICRecord;
TICRecord=packed record
Card: array[0..19] of char;
timeString: array[0..19] of char;
EmpId: array[0..9] of char;
mark: Integer;
flag: Integer;
cardTimes: Integer;
end;
Delphi相关DLL函数
function AddData(var A:integer;var Records:array of TICRecord):integer; stdcall;
var
i ,Count :integer;
begin
Count:=16;
for i:=0 to Count do
begin
Records[i].Card:='1789456456';
end;
result:=A;
end;
exports AddData;
C#结构体如下
public struct TICRecord
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 21)]
public string Card; // 卡号字符串
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 21)]
public string TimeString; // 14位刷卡时间字符串, 格式为yyyymmddhhnnss
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
public string EmpID;
public Int32 Mark; // 读卡机标识字符
public Int32 Flag; // 存储卡的结果
public Int32 CardTimes; // 发卡次数, 0-15
}
C#调用方法
[DllImport("Test.dll", EntryPoint = "AddData", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern Int32 AddData(ref Int32 A,[In,Out] TICRecord[] B, Int32 Records_Size);
TICRecord[] TICRecordList = new TICRecord[Records_Size];
int Result = DongBao.AddData(ref a, TICRecordList, Records_Size);
MessageBox.Show( "返回值:"+Result+ "");
string Str = "";
for (int i = 0; i < Records_Size; i++)
{
Str += i + " ";
Str += Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(TICRecordList[i].Card)) + "\r\n";
}
MessageBox.Show("如果成功则返回100:现在返回的是" + Str + "");
返回结果,只有第一条有记录,其他的都为空,求处理过相关问题的老师指导一下 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询