I am trying to call an unmanaged C ++ function that has a structure as an input parameter. The structure is defined in the header file as follows:
struct MyStruct
{
int siOrder;
char aaszNames[6][25];
int siId[6];
int siTones[6];
};
I tried to declare a managed structure as follows:
[StructLayoutAttribute(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct MyStruct {
public int siOrder;
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst=150)]
public string aaszNames;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst=6, ArraySubType=UnmanagedType.I4)]
public int[] siId;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst=6, ArraySubType=UnmanagedType.I4)]
public int[] siTones;
}
But without any success. I assume that marshaling fails, since aaszNames is actually an array of six 25 long zero strings. I tried declaring aasz names as
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst=150)]
public char[] aaszNames;
filling the array with zeros where necessary. But, again, nothing.
Is there something I am missing? What am I doing wrong? What is the best way to marshal this 2-D char array?
Any clues please.