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 like this:
Expand|Select|Wrap|Line Numbers
- struct MyStruct
- {
- int siOrder;
- char aaszNames[6][25];
- int siId[6];
- int siTones[6];
- };
Expand|Select|Wrap|Line Numbers
- <StructLayoutAttribute(LayoutKind.Sequential, CharSet:=CharSet.[Ansi])> _
- Public Structure MyStruct
- Public siOrder As Integer
- <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=150)> _
- Public aaszNames As String
- <MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst:=6, ArraySubType:=UnmanagedType.I4)> _
- Public siId() As Integer
- <MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst:=6, ArraySubType:=UnmanagedType.I4)> _
- Public siTones() As Integer
- End Structure
My issues are the following:
a) Marshal.SizeOf(MyStruct) is computed as 204, but as I can see, the size seems to be: 4 + 150 + 6*4 + 6*4 = 202 bytes. What are these two extra bytes, and where are they supposed to be padded?
b) How should I populate the aaszNames field? The C++ expects 6 rows of 25 character long strings, but my individual values are of less length (eg "John", "Robert", etc). How should I concatenate the string?
Could anyone give me a hint about these issues?