Hello everbody,
I want to marshal structs but I always recieve following error
"Can not marshal field ValueF of type STRUCT_B: This type can not be
marshaled as a structure field."
I have the following two structs:
typedef struct STRUCT_A
{
int ValueA;
char ValueB[64];
int ValueC;
int ValueD;
}
typedef struct STRUCT_B
{
int ValueE;
STRUCT_A ValueF[128];
int ValueG;
}
and defined the in C# as
[StructLayout(LayoutKind.Sequential)]
public class STRUCT_A
{
public Int32 ValueA;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]
public string ValueB;
public Int32 ValueC;
public Int32 ValueD;
}
and
[StructLayout(LayoutKind.Sequential)]
public struct STRUCT_B
{
public Int32 ValueE;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=128,
ArraySubType=UnmanagedType.Struct)]
public STRUCT_A[] ValueF;
public Int32 ValueG;
}
Can anyone tell me how to correctly marshal the structs?
Thanks in advance,
Lars
Mattias Sj?gren - 24 Oct 2003 11:10 GMT
Lars,
>Can anyone tell me how to correctly marshal the structs?
See if this anssers your question
http://www.dotnetinterop.com/faq/?q=StructWithStructArray
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Lars Roith - 24 Oct 2003 14:45 GMT
Mattias,
I was able to marshal the structure by hand using the description
at http://www.dotnetinterop.com/faq/default.aspx?q=VariableLengthStruct
Unfortunately I'm currently only able to marshal from IntPtr to structure.
The other way currently doesn't work. But I think it's is only a mistake in
the offsets.
Nevertheless thanks for the great help that save much time.
Lars
> Lars,
>
[quoted text clipped - 5 lines]
>
> Mattias