I wanted to marshal a struct in C++ to use it in C#. It contains nested classes inside. when I debug I get the data except for the nested classes. I am novice in custom marshalling but would be glad if someone can help me on how to get going. I have read lot of articles but they all use simple examples line int and marshal them. Custom marshalling would help me a lot as i have many structs like this to be converted.
http://blogs.msdn.com/b/jaredpar/archive/2005/07/11/437584.aspx --this example uses ints and I am struck at my first char* []
my c++ structs:
struct device
{
char Name[32];
char Port;
int type;
double Extention;
int Buttons[8];
double Matrix[4][4];
unsigned char expand[24];
}
struct InitializationParameters
{
char *SATELLITE[8];
double TOLERANCE;
BOOL AVERAGE_MODE;
int Use_DRF;
double BaseMatrix[4][4];
unsigned char expand[24];
Device MARKER[8];
};
my C# class looks like this:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class InitilizationParameters
{
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 8)]
public string[] SATELLITE=new string[8];
public double TOLERANCE;
[MarshalAs(UnmanagedType.Bool)]
public bool AVERAGE_MODE;
public int Use_DRF;
[MarshalAs(UnmanagedType.ByValArray,SizeConst = 4 * 4)]
public double[,] BaseMatrix=new double[4,4];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
public byte[] expand=new byte[24];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public Device[] MARKER=new Device[8];
}
Above marshaling gives me all data in C++ method when used with P/Invoke except for the nested class types. The above class is also marshaled similarly