private unsafe Guid GetPropertyPage(Ole32.DispatchID dispid) { try { Oleaut32.IPerPropertyBrowsing ippb = owner.GetPerPropertyBrowsing(); if (ippb is null) { return(Guid.Empty); } Guid rval = Guid.Empty; if (ippb.MapPropertyToPage(dispid, &rval).Succeeded()) { return(rval); } } catch (COMException) { } catch (Exception t) { Debug.Fail(t.ToString()); } return(Guid.Empty); }
private unsafe void EnsureArrays() { if (_arraysFetched) { return; } _arraysFetched = true; try { // Marshal the items. Oleaut32.IPerPropertyBrowsing ppb = _owner.GetPerPropertyBrowsing(); int itemCount = 0; Debug.Assert(_cookies is not null && _names is not null, "An item array is null"); if (_names.Length > 0) { object[] values = new object[_cookies.Length]; uint cookie; Debug.Assert(_cookies.Length == _names.Length, "Got uneven names and cookies"); // For each name item, we ask the object for it's corresponding value. for (int i = 0; i < _names.Length; i++) { cookie = _cookies[i]; if (_names[i] is null || !(_names[i] is string)) { Debug.Fail($"Bad IPerPropertyBrowsing item [{i}], name={_names?[i] ?? "(unknown)"}"); continue; } using var var = new Oleaut32.VARIANT(); HRESULT hr = ppb.GetPredefinedValue(_target.Dispid, cookie, &var); if (hr == HRESULT.S_OK && var.vt != Ole32.VARENUM.EMPTY) { values[i] = var.ToObject(); } itemCount++; } // Pass the data to the base Com2Enum object. if (itemCount > 0) { string[] strings = new string[itemCount]; Array.Copy(_names, 0, strings, 0, itemCount); PopulateArrays(strings, values); } } } catch (Exception ex) { Debug.Fail($"Failed to build IPerPropertyBrowsing editor. {ex.GetType().Name}, {ex.Message}"); } }
private unsafe void EnsureArrays() { if (arraysFetched) { return; } arraysFetched = true; try { // marshal the items. object[] nameItems = nameMarshaller.Items; object[] cookieItems = valueMarshaller.Items; Oleaut32.IPerPropertyBrowsing ppb = (Oleaut32.IPerPropertyBrowsing)owner.GetPerPropertyBrowsing(); int itemCount = 0; Debug.Assert(cookieItems != null && nameItems != null, "An item array is null"); if (nameItems.Length > 0) { object[] valueItems = new object[cookieItems.Length]; int cookie; Debug.Assert(cookieItems.Length == nameItems.Length, "Got uneven names and cookies"); // for each name item, we ask the object for it's corresponding value. for (int i = 0; i < nameItems.Length; i++) { cookie = (int)cookieItems[i]; if (nameItems[i] == null || !(nameItems[i] is string)) { Debug.Fail("Bad IPerPropertyBrowsing item [" + i.ToString(CultureInfo.InvariantCulture) + "], name=" + (nameItems == null ? "(unknown)" : nameItems[i].ToString())); continue; } using var var = new Oleaut32.VARIANT(); HRESULT hr = ppb.GetPredefinedValue(target.Dispid, (uint)cookie, &var); if (hr == HRESULT.S_OK && var.vt != Ole32.VARENUM.EMPTY) { valueItems[i] = var.ToObject(); } itemCount++; } // pass this data down to the base Com2Enum object... if (itemCount > 0) { string[] strings = new string[itemCount]; Array.Copy(nameItems, 0, strings, 0, itemCount); base.PopulateArrays(strings, valueItems); } } } catch (Exception ex) { Debug.Fail("Failed to build IPerPropertyBrowsing editor. " + ex.GetType().Name + ", " + ex.Message); } }