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); }
/// <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); }