예제 #1
0
        //返回值的是CommandCallResult的指针
        public IntPtr OnCommandCall(ref PlistPackageArgs args)
        {
            CommandCallResult rs = default(CommandCallResult);

            rs.FreeCommandCallResult = FreeCommandCallResult;
            rs.type = ResultType.RESULT_TEXT;//告诉SiriProxy,返回的是文本,不带任何plist xml标记的文本
            string text = null;

            if (CommandCallEvent != null)
            {
                EventArgs <CommandCallArgs> arg = new EventArgs <CommandCallArgs>((CommandCallArgs)args);
                CommandCallEvent(this, arg);
                if (!string.IsNullOrEmpty(arg.Data.ResultText))
                {
                    text = arg.Data.ResultText;
                }
                rs.type = arg.Data.Type;
            }
            if (null == text)
            {
                text = StringHelper.PtrToStringAnsi(args.responseText);//Marshal.PtrToStringAnsi(args.responseText);
            }
            rs.result_text = Marshal.StringToHGlobalAnsi(text);

            IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(rs));

            Marshal.StructureToPtr(rs, p, true);
            return(p);
        }
예제 #2
0
        public void FreeCommandCallResult(IntPtr p)
        {
            CommandCallResult rs = (CommandCallResult)Marshal.PtrToStructure(p, typeof(CommandCallResult));

            if (rs.result_text != IntPtr.Zero)
            {//释放为result_text分配的非托管内存
                Marshal.FreeHGlobal(rs.result_text);
            }
            Marshal.FreeHGlobal(p);//释放为CommandCallResult结构分配的非托管内存
        }