这是我的 DLL 导入语句:
[DllImport("KaracellLib.dll", EntryPoint = "karacell_bridge@8", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true)]
public static extern int karacell_bridge(int argumentCount, string[] argContent);
native C 代码中的实际函数定义(已转换为 DLL):
int __stdcall karacell_bridge(int argumentCount, char ** argContent )
当我多次尝试在我的 C# 代码中调用 DLL 时,我收到了提到的错误。
我已经尝试了以下方法来解决错误
- 通过进入“工具”->“调试”->“常规”抑制模块加载时的 JIT 优化(仅管理)
- 在 C# dLL 导入定义中添加了 ref:
public static extern int karacell_bridge(int argumentCount, ref string[] argContent);
感谢任何帮助!谢谢!
最佳答案
问题是因为多个线程正在调用 C# 程序中的 karacell_bridge 函数。因此,一旦我处理了它,异常就被修复了:)
关于c# - DLLImport(C 代码) C# 试图读取或写入 protected 内存。这通常表明其他内存已损坏”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12908266/