I am using a DLL built in C in my .NET application. This DLL has a function with an unsigned char* input parameter
short function_dll (unsigned char data)*
I've looking for the best calling conversion for this parameter in .NET: StringBuilder char[] byte[]
The call to the function works but randomly it fails with the error : Attempted to read or write protected memory. This is often an indication that other memory is corrupt no matter the conversion used.
This is the last thing I have tried after a lot of combinations but ... the problem persists, randomly the error arises.
[DllImport(@"myDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern short function_dll([MarshalAs(UnmanagedType.LPArray)] char[] data);
Any idea? Better conversion?
Thank you in advance, Regards.