Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / marshal6.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4
5 [StructLayout(LayoutKind.Explicit, Size=32)]
6 public class Dummy {
7         [MarshalAs(UnmanagedType.ByValTStr, SizeConst=16)]
8         [FieldOffset(0)]
9         public string   a;
10 }
11
12 public class X {
13         public static int Main () {
14                 Dummy dummy = new Dummy ();
15                 dummy.a = "abcd";
16
17                 IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Dummy)));
18                 Marshal.StructureToPtr(dummy, p, false);
19                 
20                 if(Marshal.ReadByte(p, 0) != 0x61) {
21                         return 1;
22                 }
23                 if(Marshal.ReadByte(p, 1) != 0x62) {
24                         return 1;
25                 }
26                 if(Marshal.ReadByte(p, 2) != 0x63) {
27                         return 1;
28                 }
29                 if(Marshal.ReadByte(p, 3) != 0x64) {
30                         return 1;
31                 }
32                 return 0;
33         }
34 }