10using System.Runtime.InteropServices;
16 [StructLayout(LayoutKind.Sequential)]
36 _ptr = Marshal.AllocHGlobal(_size *
ARRAY_SIZE);
43 Marshal.FreeHGlobal(_ptr);
50 int reportedSize = StructMarshal<TestMarshaledStruct>.Size;
51 Assert.That(_size, Is.EqualTo(reportedSize),
"Size must match Marshal.SizeOf.");
56 Marshal.StructureToPtr(_testStruct, _ptr,
false);
59 StructMarshal<TestMarshaledStruct>.PtrToStruct(_ptr, out output);
60 Assert.That(_testStruct.
id, Is.EqualTo(output.
id),
"Input must match output.");
65 Marshal.StructureToPtr(_testStruct, (IntPtr)((
long)_ptr + _size *
ARRAY_TEST_INDEX),
false);
68 StructMarshal<TestMarshaledStruct>.ArrayElementToStruct(_ptr,
ARRAY_TEST_INDEX, out output);
69 Assert.That(_testStruct.
id, Is.EqualTo(output.
id),
"Input must match output.");
void ArrayElementToStructTest()
const int ARRAY_TEST_INDEX
TestMarshaledStruct(int t)