在这样的 Vb6 代码中:
Public Declare Sub PLCReadWord Lib "COM3964R.dll" Alias "plc_fetchword" _
(com As Long, _
Db As Long, _
Dw As Long, _
data As Long, _
RisOper As Long)
在 C# 端转换为:
[DllImport("..\\..\\dll\\Com3964r.dll", EntryPoint = "plc_fetchword")]
public static extern void PLCReadWord(
int com,
int Db,
int Dw,
int data,
int RisOper);
使用 Visual Studio 2013 - Framework 3.5 - x86 模式编译。我的系统有 64 位 CPU 和 64 位 Windows 10。
运行程序系统时,在下面的代码中出现错误。我认为myDummyData
和myDummyError
(两种类型Int32
)都不能写:
ClassPLC.PLCReadWord(Convert.ToInt32(txtCommPort.Text),
Convert.ToInt32(txtDbRead.Text),
Convert.ToInt32(txtDwRead.Text),
myDummyData, myDummyError);
VB6 默认通过传递参数ByRef
。这对应ref
于 C#。将导入函数的 C# 声明中的所有参数更改为ref
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句