HRESULT IPropertyNotifySink.OnChanged(DispatchID dispid) { // Some controls fire OnChanged() notifications when getting values of some properties. // To prevent this kind of recursion, we check to see if we are already inside a OnChanged() call. if (Host.NoComponentChangeEvents != 0) { return(HRESULT.S_OK); } Host.NoComponentChangeEvents++; try { OnPropertyChanged(dispid); } catch (Exception t) { Debug.Fail(t.ToString()); throw; } finally { Host.NoComponentChangeEvents--; } return(HRESULT.S_OK); }
internal unsafe object GetPropertyValue(object component, string propertyName, ref bool succeeded) { if (!(component is Oleaut32.IDispatch iDispatch)) { return(null); } string[] names = new string[] { propertyName }; DispatchID dispid = DispatchID.UNKNOWN; Guid g = Guid.Empty; try { HRESULT hr = iDispatch.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &dispid); if (dispid == DispatchID.UNKNOWN || !hr.Succeeded()) { return(null); } return(GetPropertyValue(component, dispid, ref succeeded)); } catch { return(null); } }
internal bool IsNameDispId(object obj, DispatchID dispid) { if (obj is null || !obj.GetType().IsCOMObject) { return(false); } return(dispid == Com2TypeInfoProcessor.GetNameDispId((Oleaut32.IDispatch)obj)); }
object IReflect.InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) { if (name.StartsWith("[DISPID=")) { int endIndex = name.IndexOf(']'); DispatchID dispid = (DispatchID)int.Parse(name.Substring(8, endIndex - 8), CultureInfo.InvariantCulture); object ambient = host.GetAmbientProperty(dispid); if (ambient != null) { return(ambient); } } throw E_FAIL; }
internal virtual void OnPropertyChanged(DispatchID dispid) { if (Host.Site.TryGetService(out IComponentChangeService changeService)) { try { changeService.OnComponentChanging(Host); changeService.OnComponentChanged(Host); } catch (CheckoutException e) when(e == CheckoutException.Canceled) { return; } } }
public unsafe static DispatchID GetNameDispId(IDispatch obj) { DispatchID dispid = DispatchID.UNKNOWN; string[] names = null; ComNativeDescriptor cnd = ComNativeDescriptor.Instance; bool succeeded = false; // first try to find one with a valid value cnd.GetPropertyValue(obj, "__id", ref succeeded); if (succeeded) { names = new string[] { "__id" }; } else { cnd.GetPropertyValue(obj, DispatchID.Name, ref succeeded); if (succeeded) { dispid = DispatchID.Name; } else { cnd.GetPropertyValue(obj, "Name", ref succeeded); if (succeeded) { names = new string[] { "Name" }; } } } // now get the dispid of the one that worked... if (names is not null) { DispatchID pDispid = DispatchID.UNKNOWN; Guid g = Guid.Empty; HRESULT hr = obj.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &pDispid); if (hr.Succeeded()) { dispid = pDispid; } } return(dispid); }
internal object GetPropertyValue(object component, DispatchID dispid, ref bool succeeded) { if (!(component is Oleaut32.IDispatch)) { return(null); } object[] pVarResult = new object[1]; if (GetPropertyValue(component, dispid, pVarResult) == HRESULT.S_OK) { succeeded = true; return(pVarResult[0]); } else { succeeded = false; return(null); } }
public unsafe void IDispatch_GetIDsOfNames_Invoke_Success() { using var image = new Bitmap(16, 32); IPictureDisp picture = MockAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; Guid riid = Guid.Empty; var rgszNames = new string[] { "Width", "Other" }; var rgDispId = new DispatchID[rgszNames.Length]; fixed(DispatchID *pRgDispId = rgDispId) { HRESULT hr = dispatch.GetIDsOfNames(&riid, rgszNames, (uint)rgszNames.Length, Kernel32.GetThreadLocale(), pRgDispId); Assert.Equal(HRESULT.S_OK, hr); Assert.Equal(new string[] { "Width", "Other" }, rgszNames); Assert.Equal(new DispatchID[] { (DispatchID)4, DispatchID.UNKNOWN }, rgDispId); } }
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 void ITypeInfo_GetIDsOfNames_Invoke_Success() { using var image = new Bitmap(16, 32); IPictureDisp picture = SubAxHost.GetIPictureDispFromPicture(image); IDispatch dispatch = (IDispatch)picture; ITypeInfo typeInfo; HRESULT hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo); Assert.Equal(HRESULT.S_OK, hr); var rgszNames = new string[] { "Width", "Other" }; var rgDispId = new DispatchID[rgszNames.Length]; fixed(DispatchID *pRgDispId = rgDispId) { hr = typeInfo.GetIDsOfNames(rgszNames, (uint)rgszNames.Length, pRgDispId); Assert.Equal(HRESULT.S_OK, hr); Assert.Equal(new string[] { "Width", "Other" }, rgszNames); Assert.Equal(new DispatchID[] { (DispatchID)4, DispatchID.UNKNOWN }, rgDispId); } }
internal string GetName(object component) { if (!(component is Oleaut32.IDispatch)) { return(""); } DispatchID dispid = Com2TypeInfoProcessor.GetNameDispId((Oleaut32.IDispatch)component); if (dispid != DispatchID.UNKNOWN) { bool success = false; object value = GetPropertyValue(component, dispid, ref success); if (success && value != null) { return(value.ToString()); } } return(string.Empty); }
object?IReflect.InvokeMember( string name, BindingFlags invokeAttr, Binder?binder, object?target, object?[]?args, ParameterModifier[]?modifiers, CultureInfo?culture, string[]?namedParameters) { if (name.StartsWith("[DISPID=")) { int endIndex = name.IndexOf(']'); DispatchID dispid = (DispatchID)int.Parse(name.AsSpan(8, endIndex - 8), CultureInfo.InvariantCulture); object ambient = _host.GetAmbientProperty(dispid); if (ambient is not null) { return(ambient); } } throw s_unknownErrorException; }
internal virtual void OnPropertyChanged(DispatchID dispid) { try { ISite site = Host.Site; if (site is not null) { IComponentChangeService changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (changeService is not null) { try { changeService.OnComponentChanging(Host, null); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return; } throw; } // Now notify the change service that the change was successful. // changeService.OnComponentChanged(Host, null, null, null); } } } catch (Exception t) { Debug.Fail(t.ToString()); throw; } }
HRESULT IPropertyNotifySink.OnRequestEdit(DispatchID dispid) { Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "in OnRequestEdit for " + host.ToString()); return(HRESULT.S_OK); }
HRESULT IPropertyNotifySink.OnChanged(DispatchID dispid) { // Some controls fire OnChanged() notifications when getting values of some properties. // To prevent this kind of recursion, we check to see if we are already inside a OnChanged() call. if (host.NoComponentChangeEvents != 0) { return(HRESULT.S_OK); } host.NoComponentChangeEvents++; try { AxPropertyDescriptor prop = null; Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "in OnChanged"); if (dispid != DispatchID.UNKNOWN) { prop = host.GetPropertyDescriptorFromDispid(dispid); if (prop != null) { prop.OnValueChanged(host); if (!prop.SettingValue) { prop.UpdateTypeConverterAndTypeEditor(true); } } } else { // update them all for DISPID_UNKNOWN. PropertyDescriptorCollection props = ((ICustomTypeDescriptor)host).GetProperties(); foreach (PropertyDescriptor p in props) { prop = p as AxPropertyDescriptor; if (prop != null && !prop.SettingValue) { prop.UpdateTypeConverterAndTypeEditor(true); } } } ISite site = host.Site; if (site != null) { IComponentChangeService changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService)); if (changeService != null) { try { changeService.OnComponentChanging(host, prop); } catch (CheckoutException coEx) { if (coEx == CheckoutException.Canceled) { return(HRESULT.S_OK); } throw; } // Now notify the change service that the change was successful. // changeService.OnComponentChanged(host, prop, null, (prop?.GetValue(host))); } } } catch (Exception t) { Debug.Fail(t.ToString()); throw; } finally { host.NoComponentChangeEvents--; } return(HRESULT.S_OK); }
HRESULT IPropertyNotifySink.OnRequestEdit(DispatchID dispid) { return(HRESULT.S_OK); }
HRESULT IPropertyNotifySink.OnRequestEdit(DispatchID dispid) { Debug.WriteLineIf(s_axHTraceSwitch.TraceVerbose, $"in OnRequestEdit for {_host}"); return HRESULT.S_OK; }