R
Rudy Velthuis
Hello,
Does anyone know how to create a struct that will marshal to the
following C++ struct A, containing an array of the user defined String10
type:
struct String10
{
char SLen;
char S[10];
}
struct A
{
int A1;
String10 A2[20];
}
I tried:
[StructLayout(LayoutKind.Sequential)]
struct String10
{
byte SLen;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
byte[] S;
}
[StructLayout(LayoutKind.Sequential)]
struct A
{
int A1;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
String10[] A2;
}
and
Console.WriteLine(Marshal.SizeOf(typeof(A)));
But that won't marshal:
"Type A can not be marshaled as an unmanaged structure; no meaningful
size or offset can be computed."
I also tried
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
struct String10
{
byte SLen;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
string S;
}
But the problem is in the A struct, which contains an array of String10.
How I exaclty define String10 does not make a big difference. Getting
Marshal.Sizeof(String10) is not a problem.
Anyone?
Does anyone know how to create a struct that will marshal to the
following C++ struct A, containing an array of the user defined String10
type:
struct String10
{
char SLen;
char S[10];
}
struct A
{
int A1;
String10 A2[20];
}
I tried:
[StructLayout(LayoutKind.Sequential)]
struct String10
{
byte SLen;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
byte[] S;
}
[StructLayout(LayoutKind.Sequential)]
struct A
{
int A1;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
String10[] A2;
}
and
Console.WriteLine(Marshal.SizeOf(typeof(A)));
But that won't marshal:
"Type A can not be marshaled as an unmanaged structure; no meaningful
size or offset can be computed."
I also tried
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
struct String10
{
byte SLen;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
string S;
}
But the problem is in the A struct, which contains an array of String10.
How I exaclty define String10 does not make a big difference. Getting
Marshal.Sizeof(String10) is not a problem.
Anyone?