我想调用一个需要void指针作为参数的c ++函数。它将size
个字节写入指针点的位置。
在C#中,我想将一个字节数组传递给函数。
然而,当调用该函数时,我得到一个FatalExecutionEngineError
:
The runtime has encountered a fatal error. The address of the error was at 0x725cf46d, on thread 0x2328. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
我做的编组是否正确?
C#:
[DllImport("Mylib.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int MyFunction(In [MarshalAs(UnmanagedType.LPArray)] ref byte[] pData, ref int size);
C ++:
MyFunction(void *data, int *size);