I have the following C++ function:
int my_func(char* error) {
// Have access here to an Exception object called `ex`
strcpy(error, ex.what());
return 0;
}
I am PInvoking it like this in C#:
[DllImport("pHash.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int my_func(
[MarshalAs(UnmanagedType.LPStr)]
StringBuilder error);
And using like this in the code (always C# of course):
StringBuilder error = new StringBuilder();
int returnValue = my_func(error);
If I run this, the program crashes terribly (meaning that is crashes with no exception. Just closes, that's it). What am I doing wrong?