我有一個用C編寫的DLL
文件。我嘗試在我的C#代碼中使用C DLL(ImportDLL)。我的方法返回參數。 C法是正確調用,但過程中墜毀,並給出錯誤**"System.AccessViolationException: Attempted to read or write protected memory.
AccessViolationExceptiond:試圖讀/寫保護的內存
這通常是指示其他內存已損壞「**過程完成之後。
我的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 ...
);
有誰知道問題是什麼?
您是否嘗試過Google?我很確定你已經找到了一些有用的答案,即使在這裏在stackoverflow。 – 2013-04-11 08:23:34