示例#1
0
 private static void callback_A(int status, MsEmployee_Class employee)
 {
     Console.WriteLine("callback funtion A resul:{0}", status);
     Console.WriteLine("ID: {0}", employee.EmployeeID);
     Console.WriteLine("Year:{0}", employee.EmployedYear);
     Console.WriteLine("Alias: {0}", employee.Alias);
     Console.WriteLine("Name: {0}", employee.DisplayName);
     Console.WriteLine("\r\n");
 }
示例#2
0
        private static void ClassNonBlittlable()
        {
            MsEmployee_Class employee = new MsEmployee_Class();

            employee.EmployeeID = 10001;

            CPlusPlusLib.GetEmployeeInfo(employee);

            Console.WriteLine("\nemployee Info class:");
            Console.WriteLine("ID: {0}", employee.EmployeeID);
            Console.WriteLine("Year:{0}", employee.EmployedYear);
            Console.WriteLine("Alias: {0}", employee.Alias);
            Console.WriteLine("Name: {0}", employee.DisplayName);
        }
示例#3
0
 public extern static void GetEmployeeInfo([In, Out] MsEmployee_Class employee);
示例#4
0
 public extern static void CallResulOfFunction_A(MsEmployee_Class employee, CBFunction_A callback);
示例#5
0
        static void Main(string[] args)
        {
            int result1 = CPlusPlusLib.Add(1, 2);
            int result2 = CPlusPlusLib.Sub(1, 2);
            int result3 = CPlusPlusLib.Multiply(2, 2);

            Console.WriteLine(string.Format("{0} {1} {2}", result1, result2, result3));

            /////////////////////////////////////////////////////////////////////
            CPlusPlusLib.PrintMsg("\nTest CPlusPlusLib");

            string        rawString      = "12345";
            StringBuilder reversedString = new StringBuilder(rawString.Length);

            CPlusPlusLib.ReverseAnsiString(rawString, reversedString);
            Console.WriteLine(string.Format("{0} , {1}", rawString, reversedString.ToString()));

            rawString = "123456";
            string reversedStringA;

            CPlusPlusLib.ReverseStringA(rawString, out reversedStringA);
            Console.WriteLine(string.Format("{0} , {1}", rawString, reversedStringA));

            string strNew = CPlusPlusLib.GetStringNew();

            Console.WriteLine(strNew);

            IntPtr stringPtr = CPlusPlusLib.GetStringNewA();
            string strNewA   = System.Runtime.InteropServices.Marshal.PtrToStringUni(stringPtr);

            Console.WriteLine(strNewA);

            ///////////////////////////////////////////////////////////////////
            System.Diagnostics.Stopwatch mWatch = new System.Diagnostics.Stopwatch();
            const int testCycle = 600000;

            mWatch.Reset();
            mWatch.Start();
            for (int i = 0; i < testCycle; i++)
            {
                CPlusPlusLib.IsAsciiNonblittable('a');
            }
            mWatch.Stop();
            Console.WriteLine("\ntime elapsed {0}", mWatch.ElapsedTicks);

            byte mb = (byte)'a';

            mWatch.Reset();
            mWatch.Start();
            for (int i = 0; i < testCycle; i++)
            {
                CPlusPlusLib.IsAsciiBlittable(mb);
            }
            mWatch.Stop();
            Console.WriteLine("time elapsed {0}", mWatch.ElapsedTicks);

            mWatch.Reset();
            mWatch.Start();
            for (int i = 0; i < testCycle; i++)
            {
                CPlusPlusLib.IsWasciiNonblittable('a');
            }
            mWatch.Stop();
            Console.WriteLine("time elapsed {0}", mWatch.ElapsedTicks);

            //////////////////////////////////////////////////////////////////
            IntPtr pString = IntPtr.Zero;
            IntPtr result  = IntPtr.Zero;

            result = CPlusPlusLib.BSTRString(out pString);

            if (IntPtr.Zero != pString)
            {
                string argString = Marshal.PtrToStringBSTR(pString);
                Console.WriteLine("\nargument out BSTR:{0}", argString);
                // Free BSTR
                Marshal.FreeBSTR(pString);
            }

            if (IntPtr.Zero != result)
            {
                string retString = Marshal.PtrToStringBSTR(result);
                Console.WriteLine("function return BSTR:{0}", retString);
                // Free BSTR
                Marshal.FreeBSTR(result);
            }

            ///////////////////////////////////////////////////////////////////
            StructArgument();
            StructReturn();

            //////////////////////////////////////////////////////
            StructAllocString();
            StructAllocString_IntPtrString();
            ClassNonBlittlable();

            ////////////////////////////////////////////////////
            StructAsRefField();
            StructAsValField();
            StructAsValFieldFlattened();

            ///////////////////////////////////////////////////
            CharArray();
            StringArray();


            CPlusPlusLib.CBFunction cb = new CPlusPlusLib.CBFunction(callback);
            CPlusPlusLib.CallResulOfFunction(2, 6, cb);

            CPlusPlusLib.CBFunction_A cb_A     = new CPlusPlusLib.CBFunction_A(callback_A);
            MsEmployee_Class          employee = new MsEmployee_Class();

            employee.EmployeeID = 10002;
            CPlusPlusLib.CallResulOfFunction_A(employee, cb_A);

            Console.WriteLine("\r\nPress any key to exit...");
            Console.Read();
        }