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:
struct MyStruct
{
int siOrder;
char aaszNames[6][25];
int siId[6];
int siTones[6];
};
I've defined the managed structure as following:
<StructLayoutAt tribute(LayoutK ind.Sequential, CharSet:=CharSe t.[Ansi])> _
Public Structure MyStruct
Public siOrder As Integer
<MarshalAsAttri bute(UnmanagedT ype.ByValTStr, SizeConst:=150) > _
Public aaszNames As String
<MarshalAsAttri bute(UnmanagedT ype.ByValArray, SizeConst:=6, ArraySubType:=U nmanagedType.I4 )> _
Public siId() As Integer
<MarshalAsAttri bute(UnmanagedT ype.ByValArray, SizeConst:=6, ArraySubType:=U nmanagedType.I4 )> _
Public siTones() As Integer
End Structure
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:
struct MyStruct
{
int siOrder;
char aaszNames[6][25];
int siId[6];
int siTones[6];
};
I've defined the managed structure as following:
<StructLayoutAt tribute(LayoutK ind.Sequential, CharSet:=CharSe t.[Ansi])> _
Public Structure MyStruct
Public siOrder As Integer
<MarshalAsAttri bute(UnmanagedT ype.ByValTStr, SizeConst:=150) > _
Public aaszNames As String
<MarshalAsAttri bute(UnmanagedT ype.ByValArray, SizeConst:=6, ArraySubType:=U nmanagedType.I4 )> _
Public siId() As Integer
<MarshalAsAttri bute(UnmanagedT ype.ByValArray, SizeConst:=6, ArraySubType:=U nmanagedType.I4 )> _
Public siTones() As Integer
End Structure
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?
Comment