Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2ComponentEditor.cs / 1305376 / COM2ComponentEditor.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms.ComponentModel.Com2Interop { using System.Runtime.Remoting; using System.Runtime.InteropServices; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System; using System.Collections; using Microsoft.Win32; using System.Windows.Forms.Design; internal class Com2ComponentEditor : WindowsFormsComponentEditor { public static bool NeedsComponentEditor(object obj) { if (obj is NativeMethods.IPerPropertyBrowsing) { // check for a property page Guid guid = Guid.Empty; int hr = ((NativeMethods.IPerPropertyBrowsing)obj).MapPropertyToPage(NativeMethods.MEMBERID_NIL, out guid); if ((hr == NativeMethods.S_OK) && !guid.Equals(Guid.Empty)) { return true; } } if (obj is NativeMethods.ISpecifyPropertyPages) { try { NativeMethods.tagCAUUID uuids = new NativeMethods.tagCAUUID(); try { ((NativeMethods.ISpecifyPropertyPages)obj).GetPages(uuids); if (uuids.cElems > 0) { return true; } } finally { if (uuids.pElems != IntPtr.Zero) { Marshal.FreeCoTaskMem(uuids.pElems); } } } catch { } return false; } return false; } [ SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters") // This was shipped in Everett. ] public override bool EditComponent(ITypeDescriptorContext context, object obj, IWin32Window parent) { IntPtr handle = (parent == null ? IntPtr.Zero : parent.Handle); // try to get the page guid if (obj is NativeMethods.IPerPropertyBrowsing) { // check for a property page Guid guid = Guid.Empty; int hr = ((NativeMethods.IPerPropertyBrowsing)obj).MapPropertyToPage(NativeMethods.MEMBERID_NIL, out guid); if (hr == NativeMethods.S_OK) { if (!guid.Equals(Guid.Empty)) { object o = obj; SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(parent, handle), 0, 0, "PropertyPages", 1, ref o, 1, new Guid[]{guid}, Application.CurrentCulture.LCID, 0, IntPtr.Zero); return true; } } } if (obj is NativeMethods.ISpecifyPropertyPages) { bool failed = false; Exception failureException; try { NativeMethods.tagCAUUID uuids = new NativeMethods.tagCAUUID(); try { ((NativeMethods.ISpecifyPropertyPages)obj).GetPages(uuids); if (uuids.cElems <= 0) { return false; } } catch { return false; } try { object o = obj; SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(parent, handle), 0, 0, "PropertyPages", 1, ref o, uuids.cElems, new HandleRef(uuids, uuids.pElems), Application.CurrentCulture.LCID, 0, IntPtr.Zero); return true; } finally { if (uuids.pElems != IntPtr.Zero) { Marshal.FreeCoTaskMem(uuids.pElems); } } } catch (Exception ex1) { failed = true; failureException = ex1; } if (failed) { String errString = SR.GetString(SR.ErrorPropertyPageFailed); IUIService uiSvc = (context != null) ? ((IUIService) context.GetService(typeof(IUIService))) : null; if (uiSvc == null) { RTLAwareMessageBox.Show(null, errString, SR.GetString(SR.PropertyGridTitle), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0); } else if (failureException != null) { uiSvc.ShowError(failureException, errString); } else { uiSvc.ShowError(errString); } } } return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TiffBitmapEncoder.cs
- CopyOfAction.cs
- Maps.cs
- GuidConverter.cs
- TypeLoadException.cs
- DecimalConverter.cs
- CriticalFinalizerObject.cs
- MenuItemStyleCollection.cs
- MessagingActivityHelper.cs
- SmiConnection.cs
- QuotedStringWriteStateInfo.cs
- PropertyEmitter.cs
- ButtonStandardAdapter.cs
- WorkflowTransactionService.cs
- GeometryConverter.cs
- BridgeDataRecord.cs
- XmlStringTable.cs
- PartitionedDataSource.cs
- Array.cs
- BindingCollection.cs
- Int32CAMarshaler.cs
- OleDbRowUpdatedEvent.cs
- IpcChannel.cs
- ModelVisual3D.cs
- StreamUpgradeBindingElement.cs
- StringUtil.cs
- Mapping.cs
- UrlPath.cs
- CultureInfoConverter.cs
- DateTimeOffsetAdapter.cs
- TextEditorContextMenu.cs
- CompiledXpathExpr.cs
- ArgIterator.cs
- NumberFunctions.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- RunClient.cs
- PageHandlerFactory.cs
- Converter.cs
- SQLInt32Storage.cs
- DesignTimeParseData.cs
- TextTreeNode.cs
- HttpCapabilitiesEvaluator.cs
- OdbcUtils.cs
- LicenseContext.cs
- CurrencyManager.cs
- __Filters.cs
- RecordBuilder.cs
- BindingGroup.cs
- MembershipSection.cs
- ClientFormsAuthenticationCredentials.cs
- ValidationErrorEventArgs.cs
- XmlSchemaComplexContentRestriction.cs
- BitmapScalingModeValidation.cs
- DPCustomTypeDescriptor.cs
- TraceSection.cs
- Label.cs
- CollectionsUtil.cs
- EventTrigger.cs
- Delegate.cs
- WhitespaceRule.cs
- CategoryValueConverter.cs
- TraceHwndHost.cs
- FormatterConverter.cs
- RuntimeConfig.cs
- _ListenerResponseStream.cs
- PersonalizationEntry.cs
- MapPathBasedVirtualPathProvider.cs
- ShaderEffect.cs
- Int64Animation.cs
- GroupLabel.cs
- LayoutEvent.cs
- C14NUtil.cs
- ColorInterpolationModeValidation.cs
- SourceCollection.cs
- SettingsProperty.cs
- DesignTimeDataBinding.cs
- RMPermissions.cs
- ResourceContainer.cs
- CustomLineCap.cs
- ColorMatrix.cs
- VariantWrapper.cs
- ToolStripOverflowButton.cs
- FunctionQuery.cs
- TextWriterTraceListener.cs
- MoveSizeWinEventHandler.cs
- WindowsComboBox.cs
- BridgeDataRecord.cs
- OuterGlowBitmapEffect.cs
- TextFormatterHost.cs
- StatusBar.cs
- webproxy.cs
- ReferenceConverter.cs
- WebBrowserNavigatingEventHandler.cs
- TabControl.cs
- LinkUtilities.cs
- AuthenticationConfig.cs
- _ConnectionGroup.cs
- DataGridViewImageCell.cs
- SmtpException.cs
- XmlParserContext.cs