コード例 #1
0
ファイル: HtmlElement.cs プロジェクト: 15835229565/winforms-1
        public unsafe object InvokeMember(string methodName, params object[] parameter)
        {
            object retVal = null;

            NativeMethods.tagDISPPARAMS dp = new NativeMethods.tagDISPPARAMS
            {
                rgvarg = IntPtr.Zero
            };
            try
            {
                if (NativeHtmlElement is UnsafeNativeMethods.IDispatch scriptObject)
                {
                    Guid             g      = Guid.Empty;
                    string[]         names  = new string[] { methodName };
                    Ole32.DispatchID dispid = Ole32.DispatchID.UNKNOWN;
                    HRESULT          hr     = scriptObject.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &dispid);
                    if (hr.Succeeded() && dispid != Ole32.DispatchID.UNKNOWN)
                    {
                        // Reverse the arg order below so that parms are read properly thru IDispatch. (
                        if (parameter != null)
                        {
                            // Reverse the parm order so that they read naturally after IDispatch. (
                            Array.Reverse(parameter);
                        }
                        dp.rgvarg            = (parameter == null) ? IntPtr.Zero : HtmlDocument.ArrayToVARIANTVector(parameter);
                        dp.cArgs             = (parameter == null) ? 0 : parameter.Length;
                        dp.rgdispidNamedArgs = IntPtr.Zero;
                        dp.cNamedArgs        = 0;

                        object[] retVals = new object[1];
                        hr = scriptObject.Invoke(
                            dispid,
                            ref g,
                            Kernel32.GetThreadLocale(),
                            NativeMethods.DISPATCH_METHOD,
                            dp,
                            retVals,
                            new NativeMethods.tagEXCEPINFO(),
                            null);
                        if (hr == HRESULT.S_OK)
                        {
                            retVal = retVals[0];
                        }
                    }
                }
            }
            catch (Exception ex) when(!ClientUtils.IsSecurityOrCriticalException(ex))
            {
            }
            finally
            {
                if (dp.rgvarg != IntPtr.Zero)
                {
                    HtmlDocument.FreeVARIANTVector(dp.rgvarg, parameter.Length);
                }
            }

            return(retVal);
        }
コード例 #2
0
ファイル: HtmlElement.cs プロジェクト: z2516305651/winforms
        public object InvokeMember(string methodName, params object[] parameter)
        {
            object retVal = null;

            NativeMethods.tagDISPPARAMS dp = new NativeMethods.tagDISPPARAMS
            {
                rgvarg = IntPtr.Zero
            };
            try
            {
                if (NativeHtmlElement is UnsafeNativeMethods.IDispatch scriptObject)
                {
                    Guid     g       = Guid.Empty;
                    string[] names   = new string[] { methodName };
                    int[]    dispids = new int[] { NativeMethods.ActiveX.DISPID_UNKNOWN };
                    int      hr      = scriptObject.GetIDsOfNames(ref g, names, 1,
                                                                  SafeNativeMethods.GetThreadLCID(), dispids);
                    if (NativeMethods.Succeeded(hr) && (dispids[0] != NativeMethods.ActiveX.DISPID_UNKNOWN))
                    {
                        // Reverse the arg order below so that parms are read properly thru IDispatch. (
                        if (parameter != null)
                        {
                            // Reverse the parm order so that they read naturally after IDispatch. (
                            Array.Reverse(parameter);
                        }
                        dp.rgvarg            = (parameter == null) ? IntPtr.Zero : HtmlDocument.ArrayToVARIANTVector(parameter);
                        dp.cArgs             = (parameter == null) ? 0 : parameter.Length;
                        dp.rgdispidNamedArgs = IntPtr.Zero;
                        dp.cNamedArgs        = 0;

                        object[] retVals = new object[1];

                        hr = scriptObject.Invoke(dispids[0], ref g, SafeNativeMethods.GetThreadLCID(),
                                                 NativeMethods.DISPATCH_METHOD, dp,
                                                 retVals, new NativeMethods.tagEXCEPINFO(), null);
                        if (hr == NativeMethods.S_OK)
                        {
                            retVal = retVals[0];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ClientUtils.IsSecurityOrCriticalException(ex))
                {
                    throw;
                }
            }
            finally
            {
                if (dp.rgvarg != IntPtr.Zero)
                {
                    HtmlDocument.FreeVARIANTVector(dp.rgvarg, parameter.Length);
                }
            }
            return(retVal);
        }
コード例 #3
0
        /// <include file='doc\HtmlDocument.uex' path='docs/doc[@for="HtmlDocument.InvokeScript"]/*' />
        public object InvokeScript(string scriptName, object[] args)
        {
            object retVal = null;

            NativeMethods.tagDISPPARAMS dp = new NativeMethods.tagDISPPARAMS();
            dp.rgvarg = IntPtr.Zero;
            try
            {
                UnsafeNativeMethods.IDispatch scriptObject = this.NativeHtmlDocument2.GetScript() as UnsafeNativeMethods.IDispatch;
                if (scriptObject != null)
                {
                    Guid     g       = Guid.Empty;
                    string[] names   = new string[] { scriptName };
                    int[]    dispids = new int[] { NativeMethods.ActiveX.DISPID_UNKNOWN };
                    int      hr      = scriptObject.GetIDsOfNames(ref g, names, 1,
                                                                  SafeNativeMethods.GetThreadLCID(), dispids);
                    if (NativeMethods.Succeeded(hr) && (dispids[0] != NativeMethods.ActiveX.DISPID_UNKNOWN))
                    {
                        if (args != null)
                        {
                            // Reverse the arg order so that parms read naturally after IDispatch. (
                            Array.Reverse(args);
                        }
                        dp.rgvarg            = (args == null) ? IntPtr.Zero : HtmlDocument.ArrayToVARIANTVector(args);
                        dp.cArgs             = (args == null) ? 0 : args.Length;
                        dp.rgdispidNamedArgs = IntPtr.Zero;
                        dp.cNamedArgs        = 0;

                        object[] retVals = new object[1];

                        hr = scriptObject.Invoke(dispids[0], ref g, SafeNativeMethods.GetThreadLCID(),
                                                 NativeMethods.DISPATCH_METHOD, dp,
                                                 retVals, new NativeMethods.tagEXCEPINFO(), null);
                        if (hr == NativeMethods.S_OK)
                        {
                            retVal = retVals[0];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ClientUtils.IsSecurityOrCriticalException(ex))
                {
                    throw;
                }
            }
            finally
            {
                if (dp.rgvarg != IntPtr.Zero)
                {
                    HtmlDocument.FreeVARIANTVector(dp.rgvarg, args.Length);
                }
            }
            return(retVal);
        }
コード例 #4
0
        public object InvokeMember(string methodName, params object[] parameter)
        {
            object obj2 = null;

            System.Windows.Forms.NativeMethods.tagDISPPARAMS pDispParams = new System.Windows.Forms.NativeMethods.tagDISPPARAMS {
                rgvarg = IntPtr.Zero
            };
            try
            {
                System.Windows.Forms.UnsafeNativeMethods.IDispatch nativeHtmlElement = this.NativeHtmlElement as System.Windows.Forms.UnsafeNativeMethods.IDispatch;
                if (nativeHtmlElement != null)
                {
                    Guid     empty     = Guid.Empty;
                    string[] rgszNames = new string[] { methodName };
                    int[]    rgDispId  = new int[] { -1 };
                    if (!System.Windows.Forms.NativeMethods.Succeeded(nativeHtmlElement.GetIDsOfNames(ref empty, rgszNames, 1, System.Windows.Forms.SafeNativeMethods.GetThreadLCID(), rgDispId)) || (rgDispId[0] == -1))
                    {
                        return(obj2);
                    }
                    if (parameter != null)
                    {
                        Array.Reverse(parameter);
                    }
                    pDispParams.rgvarg            = (parameter == null) ? IntPtr.Zero : HtmlDocument.ArrayToVARIANTVector(parameter);
                    pDispParams.cArgs             = (parameter == null) ? 0 : parameter.Length;
                    pDispParams.rgdispidNamedArgs = IntPtr.Zero;
                    pDispParams.cNamedArgs        = 0;
                    object[] pVarResult = new object[1];
                    if (nativeHtmlElement.Invoke(rgDispId[0], ref empty, System.Windows.Forms.SafeNativeMethods.GetThreadLCID(), 1, pDispParams, pVarResult, new System.Windows.Forms.NativeMethods.tagEXCEPINFO(), null) == 0)
                    {
                        obj2 = pVarResult[0];
                    }
                }
                return(obj2);
            }
            catch (Exception exception)
            {
                if (System.Windows.Forms.ClientUtils.IsSecurityOrCriticalException(exception))
                {
                    throw;
                }
            }
            finally
            {
                if (pDispParams.rgvarg != IntPtr.Zero)
                {
                    HtmlDocument.FreeVARIANTVector(pDispParams.rgvarg, parameter.Length);
                }
            }
            return(obj2);
        }
コード例 #5
0
        public unsafe object InvokeScript(string scriptName, object[] args)
        {
            object retVal     = null;
            var    dispParams = new Ole32.DISPPARAMS
            {
                rgvarg = IntPtr.Zero
            };

            try
            {
                if (NativeHtmlDocument2.GetScript() is UnsafeNativeMethods.IDispatch scriptObject)
                {
                    Guid             g      = Guid.Empty;
                    string[]         names  = new string[] { scriptName };
                    Ole32.DispatchID dispid = Ole32.DispatchID.UNKNOWN;
                    HRESULT          hr     = scriptObject.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &dispid);
                    if (hr.Succeeded() && dispid != Ole32.DispatchID.UNKNOWN)
                    {
                        if (args != null)
                        {
                            // Reverse the arg order so that parms read naturally after IDispatch. (
                            Array.Reverse(args);
                        }
                        dispParams.rgvarg            = (args == null) ? IntPtr.Zero : HtmlDocument.ArrayToVARIANTVector(args);
                        dispParams.cArgs             = (args == null) ? 0 : (uint)args.Length;
                        dispParams.rgdispidNamedArgs = IntPtr.Zero;
                        dispParams.cNamedArgs        = 0;

                        object[] retVals    = new object[1];
                        var      pExcepInfo = new Ole32.EXCEPINFO();

                        hr = scriptObject.Invoke(
                            dispid,
                            &g,
                            Kernel32.GetThreadLocale(),
                            Oleaut32.DISPATCH.METHOD,
                            &dispParams,
                            retVals,
                            &pExcepInfo,
                            null);
                        if (hr == HRESULT.S_OK)
                        {
                            retVal = retVals[0];
                        }
                    }
                }
            }
            catch (Exception ex) when(!ClientUtils.IsSecurityOrCriticalException(ex))
            {
            }
            finally
            {
                if (dispParams.rgvarg != IntPtr.Zero)
                {
                    HtmlDocument.FreeVARIANTVector(dispParams.rgvarg, args.Length);
                }
            }

            return(retVal);
        }