public void StructureToPtr_NonGenericType_ReturnsExpected() { var structure = new SequentialClass { i = 10, s = "hello" }; int size = Marshal.SizeOf(structure); IntPtr ptr = Marshal.AllocHGlobal(size); try { Marshal.StructureToPtr(structure, ptr, false); SequentialClass result = Assert.IsType <SequentialClass>(Marshal.PtrToStructure(ptr, typeof(SequentialClass))); Assert.Equal(10, result.i); Assert.Equal("hello", result.s); } finally { Marshal.DestroyStructure(ptr, structure.GetType()); Marshal.FreeHGlobal(ptr); } }
private static void TestAsAny() { if (String.Empty.Length > 0) { // Make sure we saw these types being used in marshalling Marshal.SizeOf <SequentialClass>(); Marshal.SizeOf <SequentialStruct>(); #if OPTIMIZED_MODE_WITHOUT_SCANNER Workaround(); #endif } SequentialClass sc = new SequentialClass(); sc.f0 = 100; sc.f1 = 1; sc.f2 = 10.0f; sc.f3 = "Hello"; AsAnyTest(sc); ThrowIfNotEquals(true, sc.f1 == 2 && sc.f2 == 11.0 && sc.f3.Equals("Ifmmp"), "AsAny marshalling scenario1 failed."); SequentialStruct ss = new SequentialStruct(); ss.f0 = 100; ss.f1 = 1; ss.f2 = 10.0f; ss.f3 = "Hello"; object o = ss; AsAnyTest(o); ss = (SequentialStruct)o; ThrowIfNotEquals(true, ss.f1 == 2 && ss.f2 == 11.0 && ss.f3.Equals("Ifmmp"), "AsAny marshalling scenario2 failed."); }
private static void TestAsAny() { if (String.Empty.Length > 0) { // Make sure we saw these types being used in marshalling Issue6063Workaround(); } SequentialClass sc = new SequentialClass(); sc.f0 = 100; sc.f1 = 1; sc.f2 = 10.0f; sc.f3 = "Hello"; AsAnyTest(sc); ThrowIfNotEquals(true, sc.f1 == 2 && sc.f2 == 11.0 && sc.f3.Equals("Ifmmp"), "AsAny marshalling scenario1 failed."); SequentialStruct ss = new SequentialStruct(); ss.f0 = 100; ss.f1 = 1; ss.f2 = 10.0f; ss.f3 = "Hello"; object o = ss; AsAnyTest(o); ss = (SequentialStruct)o; ThrowIfNotEquals(true, ss.f1 == 2 && ss.f2 == 11.0 && ss.f3.Equals("Ifmmp"), "AsAny marshalling scenario2 failed."); }
public void StructureToPtr_GenericObject_ReturnsExpected() { var structure = new SomeTestStruct { i = 10, s = "hello" }; int size = Marshal.SizeOf(structure); IntPtr ptr = Marshal.AllocHGlobal(size); try { Marshal.StructureToPtr(structure, ptr, false); var result = new SequentialClass(); Marshal.PtrToStructure(ptr, result); Assert.Equal(10, result.i); Assert.Equal("hello", result.s); } finally { Marshal.DestroyStructure(ptr, structure.GetType()); Marshal.FreeHGlobal(ptr); } }
private static void TestLayoutClassPtr() { SequentialClass ss = new SequentialClass(); ss.f0 = 100; ss.f1 = 1; ss.f2 = 10.0f; ss.f3 = "Hello"; ClassTest(ss); ThrowIfNotEquals(true, ss.f1 == 2 && ss.f2 == 11.0 && ss.f3.Equals("Ifmmp"), "LayoutClassPtr marshalling scenario1 failed."); }
public static extern SequentialClass <uint> AddSequentialClassU(SequentialClass <uint> lhs, SequentialClass <uint> rhs);
public static extern void GetSequentialClassUOut(uint e00, out SequentialClass <uint> value);
public static extern SequentialClass <char> AddSequentialClassC(SequentialClass <char> lhs, SequentialClass <char> rhs);
public static extern void GetSequentialClassCOut(char e00, out SequentialClass <char> value);
public static extern SequentialClass <long> AddSequentialClassL(SequentialClass <long> lhs, SequentialClass <long> rhs);
public static extern void GetSequentialClassLOut(long e00, out SequentialClass <long> value);
public static extern SequentialClass <bool> AddSequentialClassB(SequentialClass <bool> lhs, SequentialClass <bool> rhs);
static extern bool ClassTest([In, Out] SequentialClass ss);
public static extern SequentialClass <double> AddSequentialClassD(SequentialClass <double> lhs, SequentialClass <double> rhs);
public static extern void GetSequentialClassDOut(double e00, out SequentialClass <double> value);
public static extern void GetSequentialClassFOut(float e00, out SequentialClass <float> value);
public static extern SequentialClass <float> AddSequentialClassF(SequentialClass <float> lhs, SequentialClass <float> rhs);
public static extern void GetSequentialClassBOut(bool e00, out SequentialClass <bool> value);