Example #1
0
 public MainWindow()
 {
     InitializeComponent();
     InitialListView();
     clr = new clrClass();  //新建一个托管类对象
     clr.initialize();
     clr.prepare();
     t1.Start();
     t1.IsBackground       = true;
     TestButton.Visibility = (System.Windows.Visibility) 1;
 }
Example #2
0
        public void clr_test()
        {
            clrClass clr = new clrClass();
            string   str = "hello world!";

            clr.stringShow(str);
            double fe = 33.33;
            //clr.readDouble(ret fe);
            //int []readInt = new int[1];
            int readInt = 0;

            double[] readdbl = new double[1];
            float[]  readflt = new float[4];
            float[,] read2flt = new float[2, 3];
            unsafe
            {
                //fixed (int* pint = readInt)
                //{
                //    clr.readInt(pint);
                //}

                int *pInt = &readInt;
                clr.readInt(pInt);
                fixed(double *pdbl = readdbl)
                {
                    clr.readDouble(pdbl);
                }

                fixed(float *pflt = readflt)
                {
                    clr.readArray(pflt);
                }

                fixed(float *p2flt = read2flt)
                {
                    clr.read2Array(p2flt);
                }
            }

            Console.WriteLine(String.Format("float:{0}, single:{1}, double:{2}", sizeof(float), sizeof(Single), sizeof(double)));

            Console.WriteLine(readInt);
            Console.WriteLine(readdbl[0]);
            Console.WriteLine(readflt[0]);
            Console.WriteLine(readflt[1]);
            Console.WriteLine(readflt[2]);
            Console.WriteLine(readflt[3]);
            Console.WriteLine(read2flt[0, 0]);
            Console.WriteLine(read2flt[0, 1]);
            Console.WriteLine(read2flt[0, 2]);
            Console.WriteLine(read2flt[1, 0]);
            Console.WriteLine(read2flt[1, 1]);
            Console.WriteLine(read2flt[1, 2]);

            clr.f();
            clr.f(32);

            string str21 = "nifd:fe";

            int i = str21.IndexOf(':');

            i = str21.IndexOf(';');
            i = 12;

            JsonCall cl = new JsonCall();
            //Console.Write(cl.add(100, 200));
            //string cstr = "{\"Result\":2, \"ResultValue\":[{\"ID\":2,\"Name\":\"鲁智深\",\"Age\":230,\"Sex\":\"男\"},{\"ID\":2,\"Name\":\"鲁智深1\",\"Age\":232,\"Sex\":\"男1\"}]}";

            string cstr = createMapjson();

            // lstStudent lst =  JsonConvert.DeserializeObject<lstStudent>(cstr);
            unsafe
            {
                IntPtr intPtrStr = (IntPtr)Marshal.StringToHGlobalAnsi(cstr);
                sbyte *sbyteStr  = (sbyte *)intPtrStr;
                //cl.showstr(sbyteStr);

                IntPtr rjson = Marshal.AllocCoTaskMem(4096);
                //sbyte* p = (sbyte*)pp;
                //cl.feedstr((sbyte *)rjson);
                //string str = Marshal.PtrToStringAnsi(pp);
                cl.getReturn(sbyteStr, (sbyte *)rjson);

                //反序列化
                //  Student two = JsonConvert.DeserializeObject<Student>(Marshal.PtrToStringAnsi(pp));
                //
                //  Console.WriteLine(
                //         string.Format("学生信息  ID:{0},姓名:{1},年龄:{2},性别:{3}",
                //         two.ID, two.Name, two.Age, two.Sex));//显示结果
            }
        }