Esempio n. 1
0
    public static ByteStructPack2Explicit NewByteStructPack2Explicit(byte b1, byte b2)
    {
        ByteStructPack2Explicit u1 = new ByteStructPack2Explicit();

        u1.b1 = b1;
        u1.b2 = b2;

        return(u1);
    }
Esempio n. 2
0
 public static bool TestMethod_DoCallBack_MarshalStructByVal_ByteStructPack2Explicit_Stdcall(ByteStructPack2Explicit bspe)
 {
     Console.WriteLine("Reverse,Pinvoke,By Val,Stdcall");
     ByteStructPack2Explicit change_bspe = Helper.NewByteStructPack2Explicit(32, 32);
     Assert.True(Helper.ValidateByteStructPack2Explicit(change_bspe, bspe, "TestMethod_DoCallBack_MarshalStructByVal_ByteStructPack2Explicit_Stdcall"));
     //changed the value
     bspe.b1 = 64;
     bspe.b2 = 64;
     return true;
 }
Esempio n. 3
0
 public static bool TestMethod_DoCallBack_MarshalStructByRef_ByteStructPack2Explicit_Cdecl(ref ByteStructPack2Explicit bspe)
 {
     Console.WriteLine("Reverse,Pinvoke,By Ref,Cdecl");
     ByteStructPack2Explicit change_bspe = Helper.NewByteStructPack2Explicit(64, 64);
     Assert.True(Helper.ValidateByteStructPack2Explicit(change_bspe, bspe, "TestMethod_DoCallBack_MarshalStructByRef_ByteStructPack2Explicit_Cdecl"));
     //changed the value
     bspe.b1 = 32;
     bspe.b2 = 32;
     return true;
 }
Esempio n. 4
0
 public static bool ValidateByteStructPack2Explicit(ByteStructPack2Explicit str1, ByteStructPack2Explicit str2, string methodName)
 {
     if (str1.b1 != str2.b1 || str1.b2 != str2.b2)
     {
         Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected.");
         Console.WriteLine("\tThe Actual is...");
         PrintByteStructPack2Explicit(str1, str1.ToString());
         Console.WriteLine("\tThe Expected is...");
         PrintByteStructPack2Explicit(str2, str2.ToString());
         return(false);
     }
     else
     {
         Console.WriteLine("\tPASSED!");
         return(true);
     }
 }
Esempio n. 5
0
 public static bool ValidateByteStructPack2Explicit(ByteStructPack2Explicit str1, ByteStructPack2Explicit str2, string methodName)
 {
     if (str1.b1 != str2.b1 || str1.b2 != str2.b2)
     {
         Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected.");
         Console.WriteLine("\tThe Actual is...");
         PrintByteStructPack2Explicit(str1, str1.ToString());
         Console.WriteLine("\tThe Expected is...");
         PrintByteStructPack2Explicit(str2, str2.ToString());
         return false;
     }
     else
     {
         Console.WriteLine("\tPASSED!");
         return true;
     }
 }
Esempio n. 6
0
 public static void PrintByteStructPack2Explicit(ByteStructPack2Explicit str1, string name)
 {
     Console.WriteLine("\t{0}.b1 = {1}", name, str1.b1);
     Console.WriteLine("\t{0}.b2 = {1}", name, str1.b2);
 }
Esempio n. 7
0
    public static ByteStructPack2Explicit NewByteStructPack2Explicit(byte b1, byte b2)
    {
        ByteStructPack2Explicit u1 = new ByteStructPack2Explicit();
        u1.b1 = b1;
        u1.b2 = b2;

        return u1;
    }
Esempio n. 8
0
 public static void PrintByteStructPack2Explicit(ByteStructPack2Explicit str1, string name)
 {
     Console.WriteLine("\t{0}.b1 = {1}", name, str1.b1);
     Console.WriteLine("\t{0}.b2 = {1}", name, str1.b2);
 }
 static extern bool MarshalStructAsParam_AsExpByRefOutByteStructPack2Explicit(out ByteStructPack2Explicit str1);
Esempio n. 10
0
 static extern bool MarshalStructAsParam_AsExpByValByteStructPack2Explicit(ByteStructPack2Explicit str1);
Esempio n. 11
0
    private static void TestMethod_DelegatePInvoke_MarshalByRef_Cdecl(StructID structid)
    {
        Console.WriteLine("Delegate,Pinvoke,By Ref,Cdecl");

        switch (structid)
        {
        case StructID.INNER2Id:
            INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string");
            INNER2 changeINNER2 = Helper.NewINNER2(77, 77.0F, "changed string");
            DelegateCdeclByRef_INNER2 caller_INNER2 = Get_MarshalStructAsParam_AsExpByRefINNER2_Cdecl_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByRefINNER2_Cdecl_FuncPtr...");
            Assert.IsTrue(caller_INNER2(ref sourceINNER2));
            Assert.IsTrue(Helper.ValidateINNER2(sourceINNER2, changeINNER2, "Get_MarshalStructAsParam_AsExpByRefINNER2_Cdecl_FuncPtr"));
            break;

        case StructID.InnerExplicitId:
            InnerExplicit sourceInnerExplicit = new InnerExplicit();
            sourceInnerExplicit.f1 = 1;
            sourceInnerExplicit.f3 = "some string";
            InnerExplicit changeInnerExplicit = new InnerExplicit();
            changeInnerExplicit.f1 = 77;
            changeInnerExplicit.f3 = "changed string";
            DelegateCdeclByRef_InnerExplicit caller_InnerExplicit = Get_MarshalStructAsParam_AsExpByRefInnerExplicit_Cdecl_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByRefInnerExplicit_Cdecl_FuncPtr...");
            Assert.IsTrue(caller_InnerExplicit(ref sourceInnerExplicit));
            Assert.IsTrue(Helper.ValidateInnerExplicit(sourceInnerExplicit, changeInnerExplicit, "Get_MarshalStructAsParam_AsExpByRefInnerExplicit_Cdecl_FuncPtr"));
            break;

        case StructID.InnerArrayExplicitId:
            InnerArrayExplicit sourceInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2");
            InnerArrayExplicit changeInnerArrayExplicit = Helper.NewInnerArrayExplicit(77, 77.0F, "change string1", "change string2");
            DelegateCdeclByRef_InnerArrayExplicit caller_InnerArrayExplicit = Get_MarshalStructAsParam_AsExpByRefInnerArrayExplicit_Cdecl_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByRefInnerArrayExplicit_Cdecl_FuncPtr...");
            Assert.IsTrue(caller_InnerArrayExplicit(ref sourceInnerArrayExplicit));
            Assert.IsTrue(Helper.ValidateInnerArrayExplicit(sourceInnerArrayExplicit, changeInnerArrayExplicit, "Get_MarshalStructAsParam_AsExpByRefInnerArrayExplicit_Cdecl_FuncPtr"));
            break;

        case StructID.OUTER3Id:
            OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string");
            OUTER3 changeOUTER3 = Helper.NewOUTER3(77, 77.0F, "changed string", "changed string");
            DelegateCdeclByRef_OUTER3 caller_OUTER3 = Get_MarshalStructAsParam_AsExpByRefOUTER3_Cdecl_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByRefOUTER3_Cdecl_FuncPtr...");
            Assert.IsTrue(caller_OUTER3(ref sourceOUTER3));
            Assert.IsTrue(Helper.ValidateOUTER3(sourceOUTER3, changeOUTER3, "Get_MarshalStructAsParam_AsExpByRefOUTER3_Cdecl_FuncPtr"));
            break;

        case StructID.UId:
            U sourceU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue,
                                    byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2);
            U changeU = Helper.NewU(Int32.MaxValue, UInt32.MinValue, new IntPtr(-64), new UIntPtr(64), short.MaxValue, ushort.MinValue,
                                    byte.MaxValue, sbyte.MinValue, long.MaxValue, ulong.MinValue, 64.0F, 6.4);
            DelegateCdeclByRef_U caller_U = Get_MarshalStructAsParam_AsExpByRefU_Cdecl_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByRefU_Cdecl_FuncPtr...");
            Assert.IsTrue(caller_U(ref sourceU));
            Assert.IsTrue(Helper.ValidateU(sourceU, changeU, "Get_MarshalStructAsParam_AsExpByRefU_Cdecl_FuncPtr"));
            break;

        case StructID.ByteStructPack2ExplicitId:
            ByteStructPack2Explicit source_bspe = Helper.NewByteStructPack2Explicit(32, 32);
            ByteStructPack2Explicit change_bspe = Helper.NewByteStructPack2Explicit(64, 64);
            DelegateCdeclByRef_ByteStructPack2Explicit caller_ByteStructPack2Explicit = Get_MarshalStructAsParam_AsExpByRefByteStructPack2Explicit_Cdecl_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByRefByteStructPack2Explicit_Cdecl_FuncPtr...");
            Assert.IsTrue(caller_ByteStructPack2Explicit(ref source_bspe));
            Assert.IsTrue(Helper.ValidateByteStructPack2Explicit(source_bspe, change_bspe, "Get_MarshalStructAsParam_AsExpByRefByteStructPack2Explicit_Cdecl_FuncPtr"));
            break;

        case StructID.ShortStructPack4ExplicitId:
            ShortStructPack4Explicit source_sspe = Helper.NewShortStructPack4Explicit(32, 32);
            ShortStructPack4Explicit change_sspe = Helper.NewShortStructPack4Explicit(64, 64);
            DelegateCdeclByRef_ShortStructPack4Explicit caller_ShortStructPack4Explicit = Get_MarshalStructAsParam_AsExpByRefShortStructPack4Explicit_Cdecl_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByRefShortStructPack4Explicit_Cdecl_FuncPtr...");
            Assert.IsTrue(caller_ShortStructPack4Explicit(ref source_sspe));
            Assert.IsTrue(Helper.ValidateShortStructPack4Explicit(source_sspe, change_sspe, "Get_MarshalStructAsParam_AsExpByRefShortStructPack4Explicit_Cdecl_FuncPtr"));
            break;

        case StructID.IntStructPack8ExplicitId:
            IntStructPack8Explicit source_ispe = Helper.NewIntStructPack8Explicit(32, 32);
            IntStructPack8Explicit change_ispe = Helper.NewIntStructPack8Explicit(64, 64);
            DelegateCdeclByRef_IntStructPack8Explicit caller_IntStructPack8Explicit = Get_MarshalStructAsParam_AsExpByRefIntStructPack8Explicit_Cdecl_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByRefIntStructPack8Explicit_Cdecl_FuncPtr...");
            Assert.IsTrue(caller_IntStructPack8Explicit(ref source_ispe));
            Assert.IsTrue(Helper.ValidateIntStructPack8Explicit(source_ispe, change_ispe, "Get_MarshalStructAsParam_AsExpByRefIntStructPack8Explicit_Cdecl_FuncPtr"));
            break;

        case StructID.LongStructPack16ExplicitId:
            LongStructPack16Explicit source_lspe = Helper.NewLongStructPack16Explicit(32, 32);
            LongStructPack16Explicit change_lspe = Helper.NewLongStructPack16Explicit(64, 64);
            DelegateCdeclByRef_LongStructPack16Explicit caller_LongStructPack16Explicit = Get_MarshalStructAsParam_AsExpByRefLongStructPack16Explicit_Cdecl_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByRefLongStructPack16Explicit_Cdecl_FuncPtr...");
            Assert.IsTrue(caller_LongStructPack16Explicit(ref source_lspe));
            Assert.IsTrue(Helper.ValidateLongStructPack16Explicit(source_lspe, change_lspe, "Get_MarshalStructAsParam_AsExpByRefLongStructPack16Explicit_Cdecl_FuncPtr"));
            break;

        default:
            Assert.Fail("TestMethod_DelegatePInvoke_MarshalByRef_Cdecl:The structid (Managed Side) is wrong");
            break;
        }
    }
Esempio n. 12
0
    private static void TestMethod_DelegatePInvoke_MarshalByVal_Stdcall(StructID structid)
    {
        Console.WriteLine("Delegate,Pinvoke,By Val,Stdcall");

        switch (structid)
        {
        case StructID.INNER2Id:
            INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string");
            INNER2 cloneINNER2  = Helper.NewINNER2(1, 1.0F, "some string");
            DelegateStdcallByVal_INNER2 caller_INNER2 = Get_MarshalStructAsParam_AsExpByValINNER2_Stdcall_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByValINNER2_Stdcall_FuncPtr...");
            Assert.True(caller_INNER2(sourceINNER2));
            Assert.True(Helper.ValidateINNER2(sourceINNER2, cloneINNER2, "Get_MarshalStructAsParam_AsExpByValINNER2_Stdcall_FuncPtr"));
            break;

        case StructID.InnerExplicitId:
            InnerExplicit sourceInnerExplicit = new InnerExplicit();
            sourceInnerExplicit.f1 = 1;
            sourceInnerExplicit.f3 = "some string";
            InnerExplicit cloneInnerExplicit = new InnerExplicit();
            cloneInnerExplicit.f1 = 1;
            cloneInnerExplicit.f3 = "some string";
            DelegateStdcallByVal_InnerExplicit caller_InnerExplicit = Get_MarshalStructAsParam_AsExpByValInnerExplicit_Stdcall_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByValInnerExplicit_Stdcall_FuncPtr...");
            Assert.True(caller_InnerExplicit(sourceInnerExplicit));
            Assert.True(Helper.ValidateInnerExplicit(sourceInnerExplicit, cloneInnerExplicit, "Get_MarshalStructAsParam_AsExpByValInnerExplicit_Stdcall_FuncPtr"));
            break;

        case StructID.InnerArrayExplicitId:
            InnerArrayExplicit sourceInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2");
            InnerArrayExplicit cloneInnerArrayExplicit  = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2");
            DelegateStdcallByVal_InnerArrayExplicit caller_InnerArrayExplicit = Get_MarshalStructAsParam_AsExpByValInnerArrayExplicit_Stdcall_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByValInnerArrayExplicit_Stdcall_FuncPtr...");
            Assert.True(caller_InnerArrayExplicit(sourceInnerArrayExplicit));
            Assert.True(Helper.ValidateInnerArrayExplicit(sourceInnerArrayExplicit, cloneInnerArrayExplicit, "Get_MarshalStructAsParam_AsExpByValInnerArrayExplicit_Stdcall_FuncPtr"));
            break;

        case StructID.OUTER3Id:
            OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string");
            OUTER3 cloneOUTER3  = Helper.NewOUTER3(1, 1.0F, "some string", "some string");
            DelegateStdcallByVal_OUTER3 caller_OUTER3 = Get_MarshalStructAsParam_AsExpByValOUTER3_Stdcall_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByValOUTER3_Stdcall_FuncPtr...");
            Assert.True(caller_OUTER3(sourceOUTER3));
            Assert.True(Helper.ValidateOUTER3(sourceOUTER3, cloneOUTER3, "Get_MarshalStructAsParam_AsExpByValOUTER3_Stdcall_FuncPtr"));
            break;

        case StructID.UId:
            U sourceU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue,
                                    byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2);
            U cloneU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue,
                                   byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2);
            DelegateStdcallByVal_U caller_U = Get_MarshalStructAsParam_AsExpByValU_Stdcall_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByValU_Stdcall_FuncPtr...");
            Assert.True(caller_U(sourceU));
            Assert.True(Helper.ValidateU(sourceU, cloneU, "Get_MarshalStructAsParam_AsExpByValU_Stdcall_FuncPtr"));
            break;

        case StructID.ByteStructPack2ExplicitId:
            ByteStructPack2Explicit source_bspe = Helper.NewByteStructPack2Explicit(32, 32);
            ByteStructPack2Explicit clone_bspe  = Helper.NewByteStructPack2Explicit(32, 32);
            DelegateStdcallByVal_ByteStructPack2Explicit caller_ByteStructPack2Explicit = Get_MarshalStructAsParam_AsExpByValByteStructPack2Explicit_Stdcall_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByValByteStructPack2Explicit_Stdcall_FuncPtr...");
            Assert.True(caller_ByteStructPack2Explicit(source_bspe));
            Assert.True(Helper.ValidateByteStructPack2Explicit(source_bspe, clone_bspe, "Get_MarshalStructAsParam_AsExpByValByteStructPack2Explicit_Stdcall_FuncPtr"));
            break;

        case StructID.ShortStructPack4ExplicitId:
            ShortStructPack4Explicit source_sspe = Helper.NewShortStructPack4Explicit(32, 32);
            ShortStructPack4Explicit clone_sspe  = Helper.NewShortStructPack4Explicit(32, 32);
            DelegateStdcallByVal_ShortStructPack4Explicit caller_ShortStructPack4Explicit = Get_MarshalStructAsParam_AsExpByValShortStructPack4Explicit_Stdcall_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByValShortStructPack4Explicit_Stdcall_FuncPtr...");
            Assert.True(caller_ShortStructPack4Explicit(source_sspe));
            Assert.True(Helper.ValidateShortStructPack4Explicit(source_sspe, clone_sspe, "Get_MarshalStructAsParam_AsExpByValShortStructPack4Explicit_Stdcall_FuncPtr"));
            break;

        case StructID.IntStructPack8ExplicitId:
            IntStructPack8Explicit source_ispe = Helper.NewIntStructPack8Explicit(32, 32);
            IntStructPack8Explicit clone_ispe  = Helper.NewIntStructPack8Explicit(32, 32);
            DelegateStdcallByVal_IntStructPack8Explicit caller_IntStructPack8Explicit = Get_MarshalStructAsParam_AsExpByValIntStructPack8Explicit_Stdcall_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByValIntStructPack8Explicit_Stdcall_FuncPtr...");
            Assert.True(caller_IntStructPack8Explicit(source_ispe));
            Assert.True(Helper.ValidateIntStructPack8Explicit(source_ispe, clone_ispe, "Get_MarshalStructAsParam_AsExpByValIntStructPack8Explicit_Stdcall_FuncPtr"));
            break;

        case StructID.LongStructPack16ExplicitId:
            LongStructPack16Explicit source_lspe = Helper.NewLongStructPack16Explicit(32, 32);
            LongStructPack16Explicit clone_lspe  = Helper.NewLongStructPack16Explicit(32, 32);
            DelegateStdcallByVal_LongStructPack16Explicit caller_LongStructPack16Explicit = Get_MarshalStructAsParam_AsExpByValLongStructPack16Explicit_Stdcall_FuncPtr();
            Console.WriteLine("Calling Get_MarshalStructAsParam_AsExpByValLongStructPack16Explicit_Stdcall_FuncPtr...");
            Assert.True(caller_LongStructPack16Explicit(source_lspe));
            Assert.True(Helper.ValidateLongStructPack16Explicit(source_lspe, clone_lspe, "Get_MarshalStructAsParam_AsExpByValLongStructPack16Explicit_Stdcall_FuncPtr"));
            break;

        default:
            Assert.True(false, "TestMethod_DelegatePInvoke_MarshalByRef_Stdcall:The structid (Managed Side) is wrong");
            break;
        }
    }