I have an unmanaged C++ dll which Iam trying to consume in C#.The code is as
below
//Unmanaged dll definition
typedef struct {
float a;
bool b;
char * c;
int d;
unsigned e;
unsigned char * f;
} sample;
//Managed C# dll definiton
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct sample
{
public float a;
public bool b;
public String c;
public int d;
public int e;
public int f;
}
[DllImport("sample.dll", EntryPoint="sendMessage")]
public static extern int sendMessage([In, Out] ref sample sampleStruct);
//Invoke method
sample sampleStruct = new sample();
sample.a = 2.00F;
sample.b = false;
sample.c = "A";
sample.d = 1;
sample.e = 3;
sample.f = 5;
response = sendMessage(ref sampleStruct);
Iam able to invoke and get the response but the invoked C++ method couldnt
read the structure passed.
Not sure whether my definitions are right. I have tried using
MarshalAs(UnmanagedType.LPStr) and SizeConstant but no luck
Any thoughts?Thanks