static void VerifyByValBoolArray() { var structure1 = new StructWithBoolArray() { array = new bool[] { true,true,true,true } }; int size = Marshal.SizeOf(structure1); IntPtr memory = Marshal.AllocHGlobal(size + sizeof(Int32)); try { Marshal.WriteInt32(memory, size, 0xFF); Marshal.StructureToPtr(structure1, memory, false); if (Marshal.ReadInt32(memory, size) != 0xFF) throw new Exception("Marshal.StructureToPtr buffer overwritten..."); } finally { Marshal.FreeHGlobal(memory); } }
static void VerifyByValBoolArray() { var structure1 = new StructWithBoolArray() { array = new bool[] { true, true, true, true } }; int size = Marshal.SizeOf(structure1); IntPtr memory = Marshal.AllocHGlobal(size + sizeof(Int32)); try { Marshal.WriteInt32(memory, size, 0xFF); Marshal.StructureToPtr(structure1, memory, false); if (Marshal.ReadInt32(memory, size) != 0xFF) { throw new Exception("Marshal.StructureToPtr buffer overwritten..."); } } finally { Marshal.FreeHGlobal(memory); } }