I have a function in unmanaged C / C ++ code (dll) that returns a structure containing a char array. I created a C # struct to get this return value up by calling a function. And up the call to this function, I get "System.Runtime.InteropServices.MarshalDirectiveException"
This is the C declaration:
typedef struct T_SAMPLE_STRUCT {
int num;
char text[20];
} SAMPLE_STRUCT;
SAMPLE_STRUCT sampleFunction( SAMPLE_STRUCT ss );
This is a C # declaration:
struct SAMPLE_STRUCT
{
public int num;
public string text;
}
class Dllwrapper
{
[DllImport("samplecdll.dll")]
public static extern SAMPLE_STRUCT sampleFunction(SAMPLE_STRUCT ss);
}
I am using 1 byte ASCII.
Does anyone have a clue or decision on how to do this?
source
share