/// <summary> /// Base ctor /// </summary> protected BaseCAMarshaler(NativeMethods.CA_STRUCT caStruct) : base() { if (caStruct == null) { count = 0; Debug.WriteLineIf(CAMarshalSwitch.TraceVerbose, "BaseCAMarshaler: null passed in!"); } // first 4 bytes is the count count = caStruct.cElems; caArrayAddress = caStruct.pElems; Debug.WriteLineIf(CAMarshalSwitch.TraceVerbose, "Marshaling " + count.ToString(CultureInfo.InvariantCulture) + " items of type " + ItemType.Name); }
public Int32CAMarshaler(NativeMethods.CA_STRUCT caStruct) : base(caStruct) { }
public OleStrCAMarshaler(NativeMethods.CA_STRUCT caAddr) : base(caAddr) { }
private void OnGetTypeConverterAndTypeEditor(Com2PropertyDescriptor sender, GetTypeConverterAndTypeEditorEvent gveevent) { if (sender.TargetObject is NativeMethods.IPerPropertyBrowsing) { NativeMethods.IPerPropertyBrowsing ppb = (NativeMethods.IPerPropertyBrowsing)sender.TargetObject; bool hasStrings = false; // check for enums NativeMethods.CA_STRUCT caStrings = new NativeMethods.CA_STRUCT(); NativeMethods.CA_STRUCT caCookies = new NativeMethods.CA_STRUCT(); int hr = NativeMethods.S_OK; try { hr = ppb.GetPredefinedStrings(sender.DISPID, caStrings, caCookies); } catch (ExternalException ex) { hr = ex.ErrorCode; Debug.Fail("An exception occurred inside IPerPropertyBrowsing::GetPredefinedStrings(dispid=" + sender.DISPID + "), object type=" + new ComNativeDescriptor().GetClassName(ppb) + ". This is caused by an exception (usually an AV) inside the object being browsed, and is not a problem in the properties window."); } // Terminate the existing editor if we created the current one // so if the items have disappeared, we don't hold onto the old // items. if (gveevent.TypeConverter is Com2IPerPropertyEnumConverter) { gveevent.TypeConverter = null; } if (hr != NativeMethods.S_OK) { hasStrings = false; } else { hasStrings = true; } if (hasStrings) { OleStrCAMarshaler stringMarshaler = new OleStrCAMarshaler(caStrings); Int32CAMarshaler intMarshaler = new Int32CAMarshaler(caCookies); if (stringMarshaler.Count > 0 && intMarshaler.Count > 0) { gveevent.TypeConverter = new Com2IPerPropertyEnumConverter(new Com2IPerPropertyBrowsingEnum(sender, this, stringMarshaler, intMarshaler, true)); } else { //hasStrings = false; } } // if we didn't get any strings, try the proppage edtior // if (!hasStrings) { // this is a _bit_ of a backwards-compat work around... // many older ActiveX controls will show a property page // for all properties since the old grid would only put up the // [...] button for "(Custom)". If we have a conversion editor, // don't allow this to override it... // if (sender.ConvertingNativeType) { return; } Guid g = GetPropertyPageGuid(ppb, sender.DISPID); if (!Guid.Empty.Equals(g)) { gveevent.TypeEditor = new Com2PropertyPageUITypeEditor(sender, g, (UITypeEditor)gveevent.TypeEditor); } } } }
private void OnGetTypeConverterAndTypeEditor(Com2PropertyDescriptor sender, GetTypeConverterAndTypeEditorEvent gveevent) { if (sender.TargetObject is NativeMethods.IPerPropertyBrowsing) { NativeMethods.IPerPropertyBrowsing ppb = (NativeMethods.IPerPropertyBrowsing)sender.TargetObject; bool hasStrings = false; // check for enums NativeMethods.CA_STRUCT caStrings = new NativeMethods.CA_STRUCT(); NativeMethods.CA_STRUCT caCookies = new NativeMethods.CA_STRUCT(); int hr = NativeMethods.S_OK; try { hr = ppb.GetPredefinedStrings(sender.DISPID, caStrings, caCookies); } catch(ExternalException ex){ hr = ex.ErrorCode; Debug.Fail("An exception occurred inside IPerPropertyBrowsing::GetPredefinedStrings(dispid=" + sender.DISPID + "), object type=" + new ComNativeDescriptor().GetClassName(ppb) + ". This is caused by an exception (usually an AV) inside the object being browsed, and is not a problem in the properties window."); } // Terminate the existing editor if we created the current one // so if the items have disappeared, we don't hold onto the old // items. if (gveevent.TypeConverter is Com2IPerPropertyEnumConverter) { gveevent.TypeConverter = null; } if (hr != NativeMethods.S_OK) { hasStrings = false; } else { hasStrings = true; } if (hasStrings) { OleStrCAMarshaler stringMarshaler = new OleStrCAMarshaler(caStrings); Int32CAMarshaler intMarshaler = new Int32CAMarshaler(caCookies); if (stringMarshaler.Count > 0 && intMarshaler.Count > 0) { gveevent.TypeConverter = new Com2IPerPropertyEnumConverter(new Com2IPerPropertyBrowsingEnum(sender, this, stringMarshaler, intMarshaler, true)); } else { //hasStrings = false; } } // if we didn't get any strings, try the proppage edtior // if (!hasStrings){ // this is a _bit_ of a backwards-compat work around... // many older ActiveX controls will show a property page // for all properties since the old grid would only put up the // [...] button for "(Custom)". If we have a conversion editor, // don't allow this to override it... // if (sender.ConvertingNativeType){ return; } Guid g = GetPropertyPageGuid(ppb, sender.DISPID); if (!Guid.Empty.Equals(g)){ gveevent.TypeEditor = new Com2PropertyPageUITypeEditor(sender, g, (UITypeEditor)gveevent.TypeEditor); } } } }