C#在调用C++提供的dll的时候,报错“C# 尝试读取或写入受保护的内存 。这通常指示其他内存已损坏。”
System.AccessViolationException:“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”
[DllImport(xxxxx.dll)]
dll 异常导致程序崩掉,捕获不到异常,怎么处理啊,
试试动态加载调用DLL
[DllImport("xxx.dll", CallingConvention = CallingConvention.Cdecl)]
试试这样
Assembly assembly = Assembly.LoadFile("程序集路径,不能是相对路径"); // 加载程序集(EXE 或 DLL)
dynamic obj = assembly.CreateInstance("类的完全限定名(即包括命名空间)"); // 创建类的实例