System.ExecutionEngineException
。这是C ++代码:extern "C" __declspec(dllexport) int __stdcall ReadFlashCfg(int* flData);
int __stdcall ReadFlashCfg(int* flData)
{
return mctl.ReadFlashCfg(flData);
}// breakpoint here shows flData is correct
以及C#DLL包装器代码:
[DllImport(MyDllPath)]
private static extern int ReadFlashCfg(ref int[] fData);
public static int[] ReadFlashCfgNoRc()
{
var flData = new int[8];
var rc = ReadFlashCfg(ref flData); //Exception happens here
if (rc != 0) throw new Exception(rc.ToString());
return flData;
}
以及C#调用代码:
var fd = ReadFlashCfgNoRc();
C ++代码最后一行的断点显示了用正确数据填充的数组。
[在DLL包装器中从ReadFlashCfg(ref flData)
返回时发生异常。
我想我需要让C ++知道数组的大小(总是8),以便它可以正确地管理堆栈。
我知道我可以传递八个单独的int *,但必须有一种更简单的方法-可以吗?
我正在尝试将int [8]引用传递给C ++ DLL,但在返回时会在C#中引发System.ExecutionEngineException。这是C ++代码:extern“ C” __declspec(dllexport)int __stdcall ...