我使用以下方法获得了一个外部 DLL (c++):
void _stdcall Set_Config(char* config)
Run Code Online (Sandbox Code Playgroud)
我使用以下 c# 代码来调用该方法:
[DllImport(DllName,CharSet=CharSet.Auto)]
public static extern void Set_Config(String config);
Run Code Online (Sandbox Code Playgroud)
但是当我执行我的 c# 代码时,我得到一个访问违规异常或一个 System.Runtime.InteropServices.SEHException。(我的 dll 是 32 位的,我的 c# 编译器编译为 32 位)
我也尝试用 Stringbuilder 替换 String config,但结果相同。
有人可以帮助我解决这个问题或提供一些示例代码,我必须如何调用 C++ 方法?