+
+ /* ByValTStr with Unicode */
+ ByValWStrStruct s = new ByValWStrStruct ();
+
+ IntPtr p2 = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (ByValWStrStruct)));
+ Marshal.StructureToPtr(s, p2, false);
+
+ /* Check that the ByValWStr is initialized correctly */
+ for (int i = 0; i < 8; ++i)
+ if (Marshal.ReadByte (p2, i) != 0)
+ return 31;
+
+ s.s1 = "ABCD";
+ s.i = 55;
+
+ Marshal.StructureToPtr(s, p2, false);
+
+ ByValWStrStruct s2 = (ByValWStrStruct)Marshal.PtrToStructure (p2, typeof (ByValWStrStruct));
+
+ /* The fourth char is lost because of null-termination */
+ if (s2.s1 != "ABC")
+ return 32;
+
+ if (s2.i != 55)
+ return 33;
+