Пример #1
0
        public static Sstr_simple DoCdeclSimpleStruct(Sstr_simple p, ref bool retval)
        {
            IntPtr      st     = CdeclSimpleStruct(p, ref retval);
            Sstr_simple simple = (Sstr_simple)Marshal.PtrToStructure(st, typeof(Sstr_simple));

            return(simple);
        }
Пример #2
0
        public static Sstr_simple DoCdeclSimpleStruct(Sstr_simple p, ref bool retval)
        {
            IntPtr      st     = CdeclSimpleStruct(p, ref retval);
            Sstr_simple simple = Marshal.PtrToStructure <Sstr_simple>(st);

            return(simple);
        }
Пример #3
0
        public static bool PosTest2()
        {
            string s      = "Before";
            bool   retval = true;
            double d      = 3.142;
            Sstr   p      = new Sstr(100, false, s);

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

            // //cdecl calling convention
            try
            {
                TestFramework.LogInformation(" Case 2: Direct p/invoke cdecl calling convention");
                Sstr_simple simple = new Sstr_simple(100, false, d);
                simple = DoCdeclSimpleStruct(simple, 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 ((simple.a != 101) || (!simple.b) || (simple.c != 10.11))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->a=101\nSimpleStruct->b=TRUE\nSimpleStruct->c=10.11\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->a=" + simple.a + "\nSimpleStruct->b=" + simple.b + "\nSimpleStruct->c=" + simple.c + "\n");
                    TestFramework.LogError("02", "PInvokeTests->PosTest2 : Returned values are different from expected values");
                    retval = false;
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }

            // //delegate pinvoke

            // //cdecl calling convention
            try
            {
                TestFramework.LogInformation(" Case 4: Delegate p/invoke cdecl calling convention");
                Sstr_simple simple            = new Sstr_simple(100, false, d);
                CdeclSimpleStructDelegate std = GetFptrCdeclSimpleStruct(16);

                IntPtr st = std(simple, ref retval);
                simple = (Sstr_simple)Marshal.PtrToStructure(st, typeof(Sstr_simple));


                if (retval == false)
                {
                    TestFramework.LogError("01", "PInvokeTests->PosTest2 : values of passed in structure not matched with expected once on unmanaged side.");
                    return(false);
                }
                if ((simple.a != 101) || (!simple.b) || (simple.c != 10.11))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->a=101\nSimpleStruct->b=TRUE\nSimpleStruct->c=10.11\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->a=" + simple.a + "\nSimpleStruct->b=" + simple.b + "\nSimpleStruct->c=" + simple.c + "\n");
                    TestFramework.LogError("02", "PInvokeTests->PosTest2 : 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
 private static extern IntPtr CdeclSimpleStruct(Sstr_simple p, ref bool retval);
Пример #5
0
        public static bool PosTest2()
        {
            string s = "Before";
            bool retval = true;
            double d = 3.142;
            Sstr p = new Sstr(100, false, s);

            TestFramework.BeginScenario("\n\nTest #2 (Roundtrip of a simple structre by value. Verify that values updated on unmanaged side reflect on managed side)");
            //direct pinvoke
            
           // //cdecl calling convention
            try
            {
                TestFramework.LogInformation(" Case 2: Direct p/invoke cdecl calling convention");
                Sstr_simple simple = new Sstr_simple(100, false, d);
                simple = DoCdeclSimpleStruct(simple, 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 ((simple.a != 101) || (!simple.b) || (simple.c != 10.11))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->a=101\nSimpleStruct->b=TRUE\nSimpleStruct->c=10.11\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->a=" + simple.a + "\nSimpleStruct->b=" + simple.b + "\nSimpleStruct->c=" + simple.c + "\n");          
                    TestFramework.LogError("02", "PInvokeTests->PosTest2 : Returned values are different from expected values");
                    retval = false;
                }
            }
            catch (Exception e)
            {

                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }

           // //delegate pinvoke

           // //cdecl calling convention
            try
            {
                TestFramework.LogInformation(" Case 4: Delegate p/invoke cdecl calling convention");
                Sstr_simple simple = new Sstr_simple(100, false, d);
                CdeclSimpleStructDelegate std = GetFptrCdeclSimpleStruct(16);

                IntPtr st = std(simple, ref retval);
                simple = Marshal.PtrToStructure<Sstr_simple>(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 ((simple.a != 101) || (!simple.b) || (simple.c != 10.11))
                {
                    Console.WriteLine("\nExpected values:\n SimpleStruct->a=101\nSimpleStruct->b=TRUE\nSimpleStruct->c=10.11\n");
                    Console.WriteLine("\nActual values:\n SimpleStruct->a=" + simple.a + "\nSimpleStruct->b=" + simple.b + "\nSimpleStruct->c=" + simple.c + "\n");
                    TestFramework.LogError("02", "PInvokeTests->PosTest2 : Returned values are different from expected values");
                    retval = false;
                }
            }
            catch (Exception e)
            {
                TestFramework.LogError("03", "Unexpected exception: " + e.ToString());
                retval = false;
            }
            return retval;
        }
Пример #6
0
 public static Sstr_simple DoCdeclSimpleStruct(Sstr_simple p, ref bool retval)
 {
     IntPtr st = CdeclSimpleStruct(p, ref retval);
     Sstr_simple simple = Marshal.PtrToStructure<Sstr_simple>(st);
     return simple;
 }
Пример #7
0
 private static extern IntPtr CdeclSimpleStruct(Sstr_simple p, ref bool retval);