public static object Invoke(this IDispatch dispatch, params object[] args)
 {
     using (var argVariantArrayBlock = new CoTaskMemVariantArgsByRefBlock(args))
     {
         using (var resultVariantBlock = new CoTaskMemVariantBlock())
         {
             var dispArgs = new DISPPARAMS {
                 cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 0, rgdispidNamedArgs = IntPtr.Zero
             };
             HResult.Check(dispatch.Invoke(SpecialDispIDs.Default, ref iid, 0, DispatchFlags.Method, ref dispArgs, resultVariantBlock.Addr, out _, out _));
             return(Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr));
         }
     }
 }
Beispiel #2
0
 public static object Invoke(this IDispatchEx dispatchEx, bool asConstructor, params object[] args)
 {
     using (var argVariantArrayBlock = new CoTaskMemVariantArgsByRefBlock(args))
     {
         using (var resultVariantBlock = new CoTaskMemVariantBlock())
         {
             EXCEPINFO excepInfo;
             var       dispArgs = new DISPPARAMS {
                 cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 0, rgdispidNamedArgs = IntPtr.Zero
             };
             HResult.Check(dispatchEx.InvokeEx(SpecialDispIDs.Default, 0, asConstructor ? DispatchFlags.Construct : DispatchFlags.Method, ref dispArgs, resultVariantBlock.Addr, out excepInfo));
             return(Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr));
         }
     }
 }
        internal sealed override object ExecuteRaw(UniqueDocumentInfo documentInfo, string code, bool evaluate)
        {
            if (!evaluate)
            {
                const ScriptTextFlags flags = ScriptTextFlags.IsVisible;
                Parse(documentInfo, code, flags, IntPtr.Zero, out _);
                return(null);
            }

            using (var resultVariantBlock = new CoTaskMemVariantBlock())
            {
                const ScriptTextFlags flags = ScriptTextFlags.IsExpression;
                Parse(documentInfo, code, flags, resultVariantBlock.Addr, out _);
                return(Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr));
            }
        }
        public static object GetProperty(this IDispatchEx dispatchEx, string name, bool ignoreCase, object[] args)
        {
            int dispid;
            Marshal.ThrowExceptionForHR(dispatchEx.GetDispID(name, ignoreCase ? DispatchNameFlags.CaseInsensitive : DispatchNameFlags.CaseSensitive, out dispid));

            using (var argVariantArrayBlock = new CoTaskMemVariantArgsBlock(args))
            {
                using (var resultVariantBlock = new CoTaskMemVariantBlock())
                {
                    EXCEPINFO excepInfo;
                    var dispArgs = new DISPPARAMS { cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 0, rgdispidNamedArgs = IntPtr.Zero };
                    dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyGet, ref dispArgs, resultVariantBlock.Addr, out excepInfo);
                    return Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr);
                }
            }
        }
        public static object GetProperty(this IDispatch dispatch, string name, params object[] args)
        {
            if (!MiscHelpers.Try(out int dispid, () => dispatch.GetDispIDForName(name)))
            {
                return(Nonexistent.Value);
            }

            using (var argVariantArrayBlock = new CoTaskMemVariantArgsBlock(args))
            {
                using (var resultVariantBlock = new CoTaskMemVariantBlock())
                {
                    var dispArgs = new DISPPARAMS {
                        cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 0, rgdispidNamedArgs = IntPtr.Zero
                    };
                    HResult.Check(dispatch.Invoke(dispid, ref iid, 0, DispatchFlags.PropertyGet, ref dispArgs, resultVariantBlock.Addr, out _, out _));
                    return(Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr));
                }
            }
        }
        public static object InvokeMethod(this IDispatchEx dispatchEx, string name, bool ignoreCase, params object[] args)
        {
            var dispid = dispatchEx.GetDispIDForName(name, false, ignoreCase);

            if (dispid == SpecialDispIDs.GetEnumerator)
            {
                return(dispatchEx.GetProperty(SpecialMemberNames.NewEnum, ignoreCase, args));
            }

            using (var argVariantArrayBlock = new CoTaskMemVariantArgsByRefBlock(args))
            {
                using (var resultVariantBlock = new CoTaskMemVariantBlock())
                {
                    var dispArgs = new DISPPARAMS {
                        cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 0, rgdispidNamedArgs = IntPtr.Zero
                    };
                    HResult.Check(dispatchEx.InvokeEx(dispid, 0, DispatchFlags.Method, ref dispArgs, resultVariantBlock.Addr, out _));
                    return(Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr));
                }
            }
        }
Beispiel #7
0
        public static object GetProperty(this IDispatchEx dispatchEx, string name, bool ignoreCase, params object[] args)
        {
            int dispid;

            if (!MiscHelpers.Try(out dispid, () => dispatchEx.GetDispIDForName(name, false, ignoreCase)))
            {
                return(Nonexistent.Value);
            }

            using (var argVariantArrayBlock = new CoTaskMemVariantArgsBlock(args))
            {
                using (var resultVariantBlock = new CoTaskMemVariantBlock())
                {
                    EXCEPINFO excepInfo;
                    var       dispArgs = new DISPPARAMS {
                        cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 0, rgdispidNamedArgs = IntPtr.Zero
                    };
                    HResult.Check(dispatchEx.InvokeEx(dispid, 0, DispatchFlags.PropertyGet, ref dispArgs, resultVariantBlock.Addr, out excepInfo));
                    return(Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr));
                }
            }
        }
        internal override object Execute(string documentName, string code, bool evaluate, bool discard)
        {
            VerifyNotDisposed();

            return(ScriptInvoke(() =>
            {
                EXCEPINFO excepInfo;
                if (!evaluate)
                {
                    const ScriptTextFlags flags = ScriptTextFlags.IsVisible;
                    Parse(documentName, code, flags, IntPtr.Zero, out excepInfo, discard);
                    return null;
                }

                using (var resultVariantBlock = new CoTaskMemVariantBlock())
                {
                    const ScriptTextFlags flags = ScriptTextFlags.IsExpression;
                    Parse(documentName, code, flags, resultVariantBlock.Addr, out excepInfo, discard);
                    return Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr);
                }
            }));
        }
Beispiel #9
0
        public static object InvokeMethod(this IDispatch dispatch, string name, params object[] args)
        {
            var dispid = dispatch.GetDispIDForName(name);

            if (dispid == SpecialDispIDs.GetEnumerator)
            {
                return(dispatch.GetProperty(SpecialMemberNames.NewEnum, args));
            }

            using (var argVariantArrayBlock = new CoTaskMemVariantArgsByRefBlock(args))
            {
                using (var resultVariantBlock = new CoTaskMemVariantBlock())
                {
                    EXCEPINFO excepInfo;
                    uint      argErr;
                    var       dispArgs = new DISPPARAMS {
                        cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 0, rgdispidNamedArgs = IntPtr.Zero
                    };
                    HResult.Check(dispatch.Invoke(dispid, iid, 0, DispatchFlags.Method, ref dispArgs, resultVariantBlock.Addr, out excepInfo, out argErr));
                    return(Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr));
                }
            }
        }
 public static object Invoke(this IDispatchEx dispatchEx, object[] args)
 {
     using (var argVariantArrayBlock = new CoTaskMemVariantArgsByRefBlock(args))
     {
         using (var resultVariantBlock = new CoTaskMemVariantBlock())
         {
             EXCEPINFO excepInfo;
             var dispArgs = new DISPPARAMS { cArgs = args.Length, rgvarg = argVariantArrayBlock.Addr, cNamedArgs = 0, rgdispidNamedArgs = IntPtr.Zero };
             dispatchEx.InvokeEx(SpecialDispIDs.Default, 0, DispatchFlags.Method, ref dispArgs, resultVariantBlock.Addr, out excepInfo);
             return Marshal.GetObjectForNativeVariant(resultVariantBlock.Addr);
         }
     }
 }