下面的代码是用delphi写的dll,现在要用C#调用这个dll,请问该如何实现,期待详细实现代码,有追加分数。

一、数据结构1、商品记录结构TPluRecData=recordPlu:Integer;PluNoLen:Byte;PluNo:array[0..9]ofByte;Mar... 一、 数据结构
1、商品记录结构
TPluRecData = record
Plu: Integer;
PluNoLen: Byte;
PluNo: array[0..9] of Byte;
Mark: Byte;
F1F2: array[0..1] of Byte;
BarCodeLen: Byte;
BarCode: array[0..12] of Byte;
Slprc: Integer;
Csprc: Integer;
LabelFmt: Byte;
LabelFmt2: Byte;
BcdFmt: Byte;
BcdTyp: Byte;
Addr: Byte;
Tare: Word;
Qty: Word;
DptID: Word;
SaleDate: Word;
SaleTime: Word;
ValidDate: Word;
PackDate: Word;
PackTime: Word;
Trace: Word;
PluNameLen: Word;
PluFont: Byte;
PluName: array[0..127] of Byte;
IngreLen: Word;
IngreFont: Byte;
Ingre: array[0..127] of Byte;
DscLen: Word;
DscFont: Byte;
Dsc: array[0..127] of Byte;
IS_PRINT_SaleDate: Boolean;
IS_PRINT_SaleTime: Boolean;
IS_PRINT_ValidDate: Boolean;
IS_PRINT_PackDate: Boolean;
IS_PRINT_PackTime: Boolean;
IS_PRINT_Trace: Boolean;
IS_OPEN_Price: Boolean;
RsvData: array[0..63] of Byte;
end;
PPluRecData = ^TPluRecData;

二、 接口函数说明
商品资料操作函数
5、function DB_Read_Plu_Record(IP: PChar; Plu: Integer; PPluRec: PPluRecData): Integer; stdcall;
功能:从电子秤中获取指定的商品记录
说明:无
参数说明:IP为电子秤网络地址,例如192.168.0.16;
Plu为商品秤码;
PPluRec为商品资料记录结构
返回值:-1连接未建立 0成功 1失败(失败信息可通过DB_GetError获得)
lake_cx 的以上回答我了解,但是我要在一个点击事件中调用function DB_Read_Plu_Record(IP: PChar; Plu: Integer; PPluRec: PPluRecData): Integer; stdcall方法,但是不知道最后一个参数 PPluRec: PPluRecData 怎么传入

调用的方法:
try
{
string ipAddress = "192.168.1.16";
DB_Read_Plu_Record(ipAddress, 1, new PluRecData());
}
catch (Exception ex)
{
this.textBox1.Text = ex.Message;
}
展开
 我来答
lake_cx
2010-12-06 · TA获得超过166个赞
知道小有建树答主
回答量:209
采纳率:0%
帮助的人:177万
展开全部
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public class PluRecData
{
public int Plu;
public byte PluNoLen;
[MarshalAs(UnmanagedType.LPArray, SizeConst=10)]
public byte[] PluNo;
public byte Mark;
[MarshalAs(UnmanagedType.LPArray, SizeConst=2)]
public byte[] F1F2;
public byte BarCodeLen;
[MarshalAs(UnmanagedType.LPArray, SizeConst=13)]
public byte[] BarCode;
public int Slprc;
public int Csprc;
public byte LabelFmt;
public byte LabelFmt2;
public byte BcdFmt;
public byte BcdTyp;
public byte Addr;
public ushort Tare;
public ushort Qty;
public ushort DptID;
public ushort SaleDate;
public ushort SaleTime;
public ushort ValidDate;
public ushort PackDate;
public ushort PackTime;
public ushort Trace;
public ushort PluNameLen;
public byte PluFont;
[MarshalAs(UnmanagedType.LPArray, SizeConst=128)]
public byte[] PluName;
public ushort IngreLen;
public byte IngreFont;
[MarshalAs(UnmanagedType.LPArray, SizeConst=128)]
public byte[] Ingre;
public ushort DscLen;
public byte DscFont;
[MarshalAs(UnmanagedType.LPArray, SizeConst=128)]
public byte[] Dsc;
public bool IS_PRINT_SaleDate;
public bool IS_PRINT_SaleTime;
public bool IS_PRINT_ValidDate;
public bool IS_PRINT_PackDate;
public bool IS_PRINT_PackTime;
public bool IS_PRINT_Trace;
public bool IS_OPEN_Price;
[MarshalAs(UnmanagedType.LPArray, SizeConst=64)]
public byte[] RsvData;
}

[DllImport("XXXX.dll", CharSet=CharSet.Auto)]
public static extern int DB_Read_Plu_Record(
[MarshalAs(UnmanagedType.LPStr)]
string IP,
int Plu,
[In, MarshalAs(UnmanagedType.LPStruct)]
PluRecData PPluRec
);
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式