public unsafe object InvokeScript(string scriptName, object[] args) { object retVal = null; var dispParams = new Oleaut32.DISPPARAMS(); try { if (NativeHtmlDocument2.GetScript() is Oleaut32.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 Oleaut32.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); }
public unsafe object InvokeScript(string scriptName, object[] args) { try { if (NativeHtmlDocument2.GetScript() is Oleaut32.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) { return(null); } if (args != null) { // Reverse the arg order so that they read naturally after IDispatch. Array.Reverse(args); } using var vectorArgs = new Oleaut32.VARIANTVector(args); fixed(Oleaut32.VARIANT *pVariants = vectorArgs.Variants) { var dispParams = new Oleaut32.DISPPARAMS(); dispParams.rgvarg = pVariants; dispParams.cArgs = (uint)vectorArgs.Variants.Length; dispParams.rgdispidNamedArgs = null; dispParams.cNamedArgs = 0; var retVals = new object[1]; var excepInfo = new Oleaut32.EXCEPINFO(); hr = scriptObject.Invoke( dispid, &g, Kernel32.GetThreadLocale(), Oleaut32.DISPATCH.METHOD, &dispParams, retVals, &excepInfo, null); if (hr == HRESULT.S_OK) { return(retVals[0]); } } } } catch (Exception ex) when(!ClientUtils.IsCriticalException(ex)) { } return(null); }
internal unsafe HRESULT GetPropertyValue(object component, DispatchID dispid, object[] retval) { if (!(component is Oleaut32.IDispatch iDispatch)) { return(HRESULT.E_NOINTERFACE); } try { Guid g = Guid.Empty; var pExcepInfo = new Oleaut32.EXCEPINFO(); var dispParams = new Oleaut32.DISPPARAMS(); try { HRESULT hr = iDispatch.Invoke( dispid, &g, Kernel32.GetThreadLocale(), Oleaut32.DISPATCH.PROPERTYGET, &dispParams, retval, &pExcepInfo, null); if (hr == HRESULT.DISP_E_EXCEPTION) { return(pExcepInfo.scode); } return(hr); } catch (ExternalException ex) { return((HRESULT)ex.ErrorCode); } } catch { } return(HRESULT.E_FAIL); }
public unsafe override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { object component = context.Instance; if (Marshal.IsComObject(component) && component is Oleaut32.IDispatch pDisp) { var pExcepInfo = new Oleaut32.EXCEPINFO(); var dispParams = new Oleaut32.DISPPARAMS(); Guid g = Guid.Empty; HRESULT hr = pDisp.Invoke( Ole32.DispatchID.ABOUTBOX, &g, Kernel32.GetThreadLocale(), Oleaut32.DISPATCH.METHOD, &dispParams, null, &pExcepInfo, null); Debug.Assert(hr.Succeeded(), "Failed to launch about box."); } return(value); }