Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2ComponentEditor.cs / 1 / 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.
//------------------------------------------------------------------------------
//
// 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
- CodeCastExpression.cs
- CultureData.cs
- TextWriterTraceListener.cs
- JsonDeserializer.cs
- PtsHelper.cs
- TrackingDataItemValue.cs
- UTF7Encoding.cs
- DataGridPageChangedEventArgs.cs
- PkcsUtils.cs
- GenericPrincipal.cs
- SqlRowUpdatedEvent.cs
- SliderAutomationPeer.cs
- ToolStripItemEventArgs.cs
- PackUriHelper.cs
- EtwTrace.cs
- DataGridSortCommandEventArgs.cs
- Intellisense.cs
- XmlSchemaIdentityConstraint.cs
- StylusPointPropertyInfoDefaults.cs
- DescendantBaseQuery.cs
- DiffuseMaterial.cs
- CompoundFileDeflateTransform.cs
- DiscoveryEndpointValidator.cs
- AttributeQuery.cs
- MimePart.cs
- XmlQueryType.cs
- SerializationAttributes.cs
- CodeSubDirectory.cs
- AuthorizationRuleCollection.cs
- SafeProcessHandle.cs
- ECDiffieHellman.cs
- RootAction.cs
- PropertyValueEditor.cs
- CodeDefaultValueExpression.cs
- ElementProxy.cs
- MatrixTransform.cs
- OrderedDictionaryStateHelper.cs
- TagNameToTypeMapper.cs
- XmlImplementation.cs
- DrawingImage.cs
- SqlConnectionPoolGroupProviderInfo.cs
- PermissionAttributes.cs
- UIElementCollection.cs
- HandleCollector.cs
- CommandHelper.cs
- RuleSettings.cs
- LZCodec.cs
- AssemblyFilter.cs
- ConfigurationProperty.cs
- VirtualizingPanel.cs
- ColorConvertedBitmap.cs
- AssemblyNameProxy.cs
- PropertyConverter.cs
- UnknownExceptionActionHelper.cs
- BindingWorker.cs
- ImageBrush.cs
- QueryFunctions.cs
- XmlWrappingReader.cs
- PublisherMembershipCondition.cs
- Parser.cs
- TextView.cs
- Config.cs
- ConfigurationSectionGroupCollection.cs
- ConsumerConnectionPointCollection.cs
- XPathArrayIterator.cs
- EpmSourceTree.cs
- PropertyRef.cs
- FunctionImportElement.cs
- DispatchChannelSink.cs
- EnumValAlphaComparer.cs
- StylusButtonEventArgs.cs
- Viewport2DVisual3D.cs
- DBBindings.cs
- MarshalDirectiveException.cs
- MultipartIdentifier.cs
- IdentityHolder.cs
- Html32TextWriter.cs
- CellTreeNode.cs
- CharEntityEncoderFallback.cs
- XPathDocumentNavigator.cs
- WebHeaderCollection.cs
- EdmValidator.cs
- BoolExpr.cs
- CompilerGlobalScopeAttribute.cs
- BufferedOutputStream.cs
- LinqDataSourceHelper.cs
- HtmlLink.cs
- MailWebEventProvider.cs
- PaperSize.cs
- OpenTypeLayoutCache.cs
- CompositeDataBoundControl.cs
- SqlIdentifier.cs
- Rotation3DAnimationBase.cs
- securitycriticaldataClass.cs
- HttpApplication.cs
- ExecutionTracker.cs
- XmlTextWriter.cs
- Speller.cs
- DynamicField.cs
- InputBindingCollection.cs