Hallo everyone.
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:
I've defined the managed structure as following:
The C++ dll writes to a log file when a function is called. From this log I can see that the structure cannot be resolved.
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?
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:
Code:
struct MyStruct
{
int siOrder;
char aaszNames[6][25];
int siId[6];
int siTones[6];
};
Code:
<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?
Comment