+ return 0;
+ }
+
+ [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
+ public struct Struct1
+ {
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
+ public string Field1;
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
+ public string Field2;
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
+ public string Field3;
+ }
+
+ public static int test_0_byvaltstr () {
+ ByValTStrStruct s = new ByValTStrStruct ();
+
+ IntPtr p2 = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (ByValTStrStruct)));
+ Marshal.StructureToPtr(s, p2, false);
+
+ /* Check that the ByValTStr is initialized correctly */
+ for (int i = 0; i < 4; ++i)
+ if (Marshal.ReadByte (p2, i) != 0)
+ return 31;
+
+ s.s1 = "ABCD";
+ s.i = 55;
+
+ Marshal.StructureToPtr(s, p2, false);
+
+ ByValTStrStruct s2 = (ByValTStrStruct)Marshal.PtrToStructure (p2, typeof (ByValTStrStruct));
+
+ /* The fourth char is lost because of null-termination */
+ if (s2.s1 != "ABC")
+ return 32;
+
+ if (s2.i != 55)
+ return 33;