Align libgc vcxproj with makefile.
[mono.git] / mono / tests / marshal3.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 public class Test {
5
6
7         [StructLayout (LayoutKind.Sequential)]
8         public struct BlittableStruct {
9                 public int a;
10                 public int b;
11         }
12         
13         public unsafe static int Main () {
14                 BlittableStruct ss = new BlittableStruct ();
15                 int size = Marshal.SizeOf (typeof (BlittableStruct));
16                 
17                 Console.WriteLine ("BlittableStruct:" + size);
18                 if (size != 8)
19                         return 1;
20                 
21                 IntPtr p = Marshal.AllocHGlobal (size);
22                 ss.a = 123;
23                 ss.b = 124;
24
25                 Marshal.StructureToPtr (ss, p, false);
26                 Type t = ss.GetType ();
27                 
28                 if (Marshal.ReadInt32 (p, 0) != 123)
29                         return 1;
30                 if (Marshal.ReadInt32 (p, 4) != 124)
31                         return 1;
32
33                 BlittableStruct cp = (BlittableStruct)Marshal.PtrToStructure (p, ss.GetType ());
34
35                 if (cp.a != 123)
36                         return 2;
37
38                 if (cp.b != 124)
39                         return 2;
40                 
41                 return 0;
42         }
43 }
44