我有一个DLL
用 C 编写的文件。我尝试在我的 C# 代码中使用 C DLL (ImportDLL)。我的方法返回参数。C方法被正确调用但它在处理后崩溃并给出错误**"System.AccessViolationException: Attempted to read or write protected memory.
这通常表明其他内存在进程完成后已损坏"**。
我的 C 声明
int preProcessAndBestImagesC(
char* ...,
size_t* ...,
char** ...,
size_t* ...,
(struct)* ...,
size_t* ...,
int** ...,
(struct)** ...,
int ...,
int printStatus
);
我的 C# 声明
[DllImport(@"abc.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true, BestFitMapping = true, EntryPoint = "xxx")]
[return: MarshalAs(UnmanagedType.I4)]
unsafe private static extern int xxx(
String p_ ...,
[MarshalAs(UnmanagedType.I2)] out UInt16 p_numImageFilesOrDirs,
String[] p_vecImageFilesOrDirs,
[MarshalAs(UnmanagedType.I2)] out UInt16 ...,
[MarshalAs(UnmanagedType.LPArray)] out (struct)[] ...,
[MarshalAs(UnmanagedType.I2)] out UInt16 ...,
out Int16[] ...,
[MarshalAs(UnmanagedType.LPArray)] out (struct)[] ...,
[MarshalAs(UnmanagedType.I2)] Int16 ...,
[MarshalAs(UnmanagedType.I2)] Int16 ...
);
有谁知道问题是什么?