public class Test {
+ [StructLayout (LayoutKind.Sequential)]
+ public class SimpleObj {
+ public int a;
+ public int b;
+
+ public void test () {}
+ }
+
[StructLayout (LayoutKind.Sequential)]
public struct SimpleStruct2 {
public int a;
[MarshalAs (UnmanagedType.ByValArray, SizeConst=2)] public short[] a1;
[MarshalAs (UnmanagedType.ByValTStr, SizeConst=4)] public string s1;
public SimpleStruct2 emb1;
+ public SimpleObj emb2;
public string s2;
}
int size = Marshal.SizeOf (typeof (SimpleStruct));
Console.WriteLine ("SimpleStruct:" + size);
- if (size != 36)
+ if (size != 44)
return 1;
IntPtr p = Marshal.AllocHGlobal (size);
ss.emb1 = new SimpleStruct2 ();
ss.emb1.a = 3;
ss.emb1.b = 4;
+ ss.emb2 = new SimpleObj ();
+ ss.emb2.a = 10;
+ ss.emb2.b = 11;
ss.s2 = "just a test";
Marshal.StructureToPtr (ss, p, false);
return 1;
SimpleStruct cp = (SimpleStruct)Marshal.PtrToStructure (p, ss.GetType ());
-
+
if (cp.a != 1)
return 2;
if (cp.emb1.b != 4)
return 2;
+ if (cp.emb2.a != 10)
+ return 2;
+
+ if (cp.emb2.b != 11)
+ return 2;
+
if (cp.s2 != "just a test")
return 2;