作者:日全食x_354 | 来源:互联网 | 2023-07-31 16:22
原VB代码:DimResultAsLongDimPLUClusterAsTPLUClusterDimPLUAsTPluDimHotkeyTableAsTHotkeyTa
原VB代码:
Dim Result As Long
Dim PLUCluster As TPLUCluster
Dim PLU As TPlu
Dim HotkeyTable As THotkeyTable
Dim Str As String
Str = String(256, " ")
PLU.PLUName = "沙琪玛"
PLU.LFCode = 12345
HotkeyTable.Hotkey(0) = 12345
PLU.BarCode = 22
PLUCluster.PLU(0) = PLU
Result = PBusPLUToStr(PLU, Str)
Result = PBusConnectEx(".\lfzk.dat", ".\system.cfg", "192.168.1.87")
If (Result >= 0) Then
Result = PBusTransferPLUCluster(PLUCluster)
End If
我是在网上转换成c#的:
int Result = 0;
TPlu PLU = default(TPlu);
TPLUCluster PLUCluster = default(TPLUCluster);
THotkeyTable HotkeyTable = default(THotkeyTable);
string Str_Renamed = "";
PLU.PLUName = "沙琪玛";
PLU.LFCode = 12345;
HotkeyTable.Hotkey[0] = 12345;
PLU.BarCode = 22;
PLUCluster.PLU[0] = PLU;
Result =
PBusPLUToStr(PLU, Str_Renamed);
Result = PBusConnectEx(".\\lfzk.dat", ".\\system.cfg", "192.168.1.87");
if ((Result >= 0))
{
Result =
PBusTransferPLUCluster(PLUCluster);
}
if ((Result >= 0))
{
Result =
PBusTransferHotkey(HotkeyTable, 0);
}
红色的那3行报相同的错误:
错误 1 与“Test.Form1.PBusPLUToStr(ref Test.Form1.TPlu, string)”最匹配的重载方法具有一些无效参数
错误 2 参数“1”必须与关键字“ref”一起传递
[DllImport("PBusDrv.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int PBusTransferPLUCluster(ref TPLUCluster PLUCluster);
[DllImport("PBusDrv.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int PBusTransferHotkey(ref THotkeyTable HotkeyTable, int TableIndex);
[DllImport("PBusDrv.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int PBusPLUToStr(ref TPlu PLU, string LPStr);
请高手指点,谢谢!
5 个解决方案
public struct TPlu
{
public string PLUName;
public int LFCode;
public string Code;
public int BarCode;
public int UnitPrice;
public int WeightUnit;
public int Deptment;
public double Tare;
public int ShlefTime;
public int PackageType;
public double PackageWeight;
public int Tolerance;
public byte Message1;
public byte Reserved;
public short Reserved1;
public byte Message2;
public byte Reserved2;
public byte MultiLabel;
public byte Rebate;
public int Account;
}
public struct TPLUCluster
{
public TPlu[] PLU;
public void Initialize()
{
PLU = new TPlu[4];
}
}
public struct THotkeyTable
{
public int[] Hotkey;
public void Initialize()
{
Hotkey = new int[84];
}
}
会不会是这段定义类有问题?
报错不是说的很清楚了
PBusPLUToStr(PLU, Str_Renamed);
改成
PBusPLUToStr(ref PLU, Str_Renamed);