public static ExplStruct DoCdeclSimpleExplStruct(ExplStruct p, ref bool retval)
        {
            IntPtr     st     = CdeclSimpleExplStruct(p, ref retval);
            ExplStruct simple = Marshal.PtrToStructure <ExplStruct>(st);

            return(simple);
        }
示例#2
0
        public static ExplStruct DoCdeclSimpleExplStruct(ExplStruct p, ref bool retval)
        {
            IntPtr     st     = CdeclSimpleExplStruct(p, ref retval);
            ExplStruct simple = (ExplStruct)Marshal.PtrToStructure(st, typeof(ExplStruct));

            return(simple);
        }
示例#3
0
        public static bool PosTest4()
        {
            ExplStruct p;
            bool       retval = false;

            TestFramework.BeginScenario("\n\nTest #4 (Roundtrip of a simple structre (Explicit layout) by value. Verify that values updated on unmanaged side reflect on managed side)");
            //direct pinvoke

            //cdecl
            try
            {
                p = new ExplStruct(DialogResult.OK, false);
                TestFramework.LogInformation(" Case 2: Direct p/invoke cdecl calling convention");
                p = DoCdeclSimpleExplStruct(p, ref retval);
                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->PosTest2 : values of passed in structure not matched with expected once on unmanaged side.");
                    return(false);
                }
                if ((p.type != DialogResult.Cancel) || (p.c != 3.142))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->a=2\nSimpleStruct->c=3.142\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->a=" + p.type + "\nSimpleStruct->c=" + p.c + "\n");
                    TestFramework.LogError("02", "PInvokeTests->PosTest4 : Returned values are different from expected values");
                    retval = false;
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }

            //delegate pinvoke

            //cdecl
            try
            {
                p = new ExplStruct(DialogResult.OK, false);
                TestFramework.LogInformation(" Case 4: Direct p/invoke cdecl calling convention");

                CdeclSimpleExplStructDelegate std = GetFptrCdeclSimpleExplStruct(20);

                IntPtr st = std(p, ref retval);
                p = (ExplStruct)Marshal.PtrToStructure(st, typeof(ExplStruct));

                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->PosTest2 : values of passed in structure not matched with expected once on unmanaged side.");
                    return(false);
                }
                if ((p.type != DialogResult.Cancel) || (p.c != 3.142))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->a=2\nSimpleStruct->c=3.142\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->a=" + p.type + "\nSimpleStruct->c=" + p.c + "\n");
                    TestFramework.LogError("02", "PInvokeTests->PosTest4 : Returned values are different from expected values");
                    retval = false;
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }
            return(retval);
        }
示例#4
0
        public static bool PosTest3()
        {
            ExplStruct p;
            bool       retval = false;

            TestFramework.BeginScenario("\n\nTest #3 (Roundtrip of a simple structre (explicit layout) by reference. Verify that values updated on unmanaged side reflect on managed side)");
            //direct pinvoke

            //cdecl
            try
            {
                p = new ExplStruct(DialogResult.None, 10);
                TestFramework.LogInformation(" Case 2: Direct p/invoke cdecl calling convention");
                retval = DoCdeclSimpleExplStructByRef(ref p);

                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->PosTest3 : Unexpected error occured on unmanaged side");
                    return(false);
                }
                if ((p.type != DialogResult.OK) || (!p.b))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->type=1\nSimpleStruct->b=TRUE\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->type=" + p.type + "\nSimpleStruct->b=" + p.b);
                    TestFramework.LogError("02", "PInvokeTests->PosTest3 : Returned values are different from expected values");
                    retval = false;
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }

            //Delegate pinvoke --- cdecl
            try
            {
                p = new ExplStruct(DialogResult.None, 10);
                TestFramework.LogInformation(" Case 4: Delegate p/invoke cdecl calling convention");
                CdeclSimpleExplStructByRefDelegate std = GetFptrCdeclSimpleExplStructByRef(18);

                retval = std(ref p);

                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->PosTest3 : Unexpected error occured on unmanaged side");
                    return(false);
                }
                if ((p.type != DialogResult.OK) || (!p.b))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->type=1\nSimpleStruct->b=TRUE\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->type=" + p.type + "\nSimpleStruct->b=" + p.b);
                    TestFramework.LogError("02", "PInvokeTests->PosTest3 : Returned values are different from expected values");
                    retval = false;
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }


            return(retval);
        }
示例#5
0
 public static bool DoCdeclSimpleExplStructByRef(ref ExplStruct p)
 {
     return(CdeclSimpleExplStructByRef(ref p));
 }
示例#6
0
 private static extern bool CdeclSimpleExplStructByRef(ref ExplStruct p);
示例#7
0
 private static extern IntPtr CdeclSimpleExplStruct(ExplStruct p, ref bool retval);
示例#8
0
        public static bool PosTest4()
        {
            ExplStruct p;            
            bool retval = false;

            TestFramework.BeginScenario("\n\nTest #4 (Roundtrip of a simple structre (Explicit layout) by value. Verify that values updated on unmanaged side reflect on managed side)");
            //direct pinvoke

            //cdecl
            try
            {
                p = new ExplStruct(DialogResult.OK, false);
                TestFramework.LogInformation(" Case 2: Direct p/invoke cdecl calling convention");
                p = DoCdeclSimpleExplStruct(p, ref retval);
                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->PosTest2 : values of passed in structure not matched with expected once on unmanaged side.");
                    return false;
                }
                if ((p.type != DialogResult.Cancel) || (p.c != 3.142))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->a=2\nSimpleStruct->c=3.142\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->a=" + p.type + "\nSimpleStruct->c=" + p.c + "\n");
                    TestFramework.LogError("02", "PInvokeTests->PosTest4 : Returned values are different from expected values");
                    retval = false;
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }

            //delegate pinvoke

            //cdecl
            try
            {
                p = new ExplStruct(DialogResult.OK, false);
                TestFramework.LogInformation(" Case 4: Direct p/invoke cdecl calling convention");

                CdeclSimpleExplStructDelegate std = GetFptrCdeclSimpleExplStruct(20);

                IntPtr st = std(p, ref retval);
                p = Marshal.PtrToStructure<ExplStruct>(st);

                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->PosTest2 : values of passed in structure not matched with expected once on unmanaged side.");
                    return false;
                }
                if ((p.type != DialogResult.Cancel) || (p.c != 3.142))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->a=2\nSimpleStruct->c=3.142\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->a=" + p.type + "\nSimpleStruct->c=" + p.c + "\n");
                    TestFramework.LogError("02", "PInvokeTests->PosTest4 : Returned values are different from expected values");
                    retval = false;
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }
            return retval;
        }
示例#9
0
        public static bool PosTest3()
        {
            ExplStruct p;
            bool retval = false;

            TestFramework.BeginScenario("\n\nTest #3 (Roundtrip of a simple structre (explicit layout) by reference. Verify that values updated on unmanaged side reflect on managed side)");
            //direct pinvoke

            //cdecl
            try
            {
                p = new ExplStruct(DialogResult.None, 10);
                TestFramework.LogInformation(" Case 2: Direct p/invoke cdecl calling convention");
                retval = DoCdeclSimpleExplStructByRef(ref p);

                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->PosTest3 : Unexpected error occured on unmanaged side");
                    return false;
                }
                if ((p.type != DialogResult.OK) || (!p.b))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->type=1\nSimpleStruct->b=TRUE\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->type=" + p.type + "\nSimpleStruct->b="  + p.b);
                    TestFramework.LogError("02", "PInvokeTests->PosTest3 : Returned values are different from expected values");
                    retval = false;
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }

            //Delegate pinvoke --- cdecl
            try
            {
                p = new ExplStruct(DialogResult.None, 10);
                TestFramework.LogInformation(" Case 4: Delegate p/invoke cdecl calling convention");
                CdeclSimpleExplStructByRefDelegate std = GetFptrCdeclSimpleExplStructByRef(18);
                                                         
                retval = std(ref p); 

                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->PosTest3 : Unexpected error occured on unmanaged side");
                    return false;
                }
                if ((p.type != DialogResult.OK) || (!p.b))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->type=1\nSimpleStruct->b=TRUE\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->type=" + p.type + "\nSimpleStruct->b=" + p.b);
                    TestFramework.LogError("02", "PInvokeTests->PosTest3 : Returned values are different from expected values");
                    retval = false;
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }


            return retval;
        }
示例#10
0
 public static ExplStruct DoCdeclSimpleExplStruct(ExplStruct p, ref bool retval)
 {
     IntPtr st = CdeclSimpleExplStruct(p, ref retval);
     ExplStruct simple = Marshal.PtrToStructure<ExplStruct>(st);
     return simple;
 }
示例#11
0
 public static bool DoCdeclSimpleExplStructByRef(ref ExplStruct p)
 {
     return CdeclSimpleExplStructByRef(ref p);
 }
示例#12
0
 private static extern bool CdeclSimpleExplStructByRef(ref ExplStruct p);
示例#13
0
 private static extern IntPtr CdeclSimpleExplStruct(ExplStruct p, ref bool retval);