I have a DLL
file that is written in C. I am try to use in C DLL (ImportDLL) in my C# code. My method return out parameter. C method is called correctly but it crashed after process and gives error **"System.AccessViolationException: Attempted to read or write protected memory.
This is often an indication that other memory is corrupt"** after process completed.
My C declaration
int preProcessAndBestImagesC(
char* ...,
size_t* ...,
char** ...,
size_t* ...,
(struct)* ...,
size_t* ...,
int** ...,
(struct)** ...,
int ...,
int printStatus
);
My C# Declaration
[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 ...
);
Does anyone know what the problem is?