调用dll时c#中的访问冲突错误

哈特库巴

在这样的 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。

运行程序系统时,在下面的代码中出现错误。我认为myDummyDatamyDummyError(两种类型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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在DLL中调用外部函数时出现“访问冲突”错误(在unzipper.dll中解压缩)

从 Delphi 调用 C++ DLL 时的访问冲突

调用dll函数时发生C ++访问冲突

在多线程环境中从C#调用Delphi DLL时发生访问冲突

从Delphi“访问冲突”中正确调用DLL中的C ++函数

调用glGetString时发生访问冲突错误

调用strtok()时访问冲突 C ++

调用指针时c ++ typedef访问冲突

带有C#异常错误的C DLL(访问冲突)

使用 OpenGL 时 nvoglv64.dll 中的访问冲突

从C#调用C ++函数时发生访问冲突异常

使用自定义指标和 C++ DLL 时访问冲突读取错误和 MT4 崩溃

读取C中的字符串时发生访问冲突错误

P /调用offreg.dll函数-后续调用中的访问冲突

使用C#访问C ++ DLL时出现间歇性访问冲突

从C ++调用C DLL会导致访问冲突,但DllImport正常工作的C#项目

在 C++ 中调用虚方法会导致访问冲突

调用dll中的另一个函数会导致访问冲突

调用glutWireSphere()时的PyOpenGL访问冲突读取

在C ++中“调整大小”数组时发生访问冲突

访问DLL中的函数时出现调试断言失败错误

在进程外调用MiniDumpWriteDump中的访问冲突

使用 ctypes 的 .dll 中的 python 中的 C++ 函数 - 找不到函数和访问冲突

C#到非托管C ++ DLL访问冲突/“框架不在模块中”

从Cocoa中的C api调用Swift闭包时出现访问错误

使用Ctypes与Fortran DLL进行接口时发生访问冲突

PyQt5 中的访问冲突错误

C++访问冲突读取位置错误

调用DLL时发生奇怪的内存访问