Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Messaging / System / Messaging / Interop / SafeHandles.cs / 1305376 / SafeHandles.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Messaging.Interop { using System; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; internal class MessageQueueHandle : SafeHandleZeroOrMinusOneIsInvalid { public static readonly MessageQueueHandle InvalidHandle = new InvalidMessageQueueHandle(); MessageQueueHandle() : base(true) {} protected override bool ReleaseHandle() { SafeNativeMethods.MQCloseQueue(this.handle); return true; } public override bool IsInvalid { get { return base.IsInvalid || IsClosed; } } // A subclass needed to express InvalidHandle. The reason is that CLR notices that // ReleaseHandle requires a call to MQRT.DLL, and throws in the ctor if MQRT.DLL is not available, // even though CTOR ITSELF DOES NOT REQUIRE MQRT.DLL. // We address this by defining a NOOP ReleaseHandle sealed class InvalidMessageQueueHandle : MessageQueueHandle { protected override bool ReleaseHandle() { return true; } } } internal class CursorHandle : SafeHandleZeroOrMinusOneIsInvalid { public static readonly CursorHandle NullHandle = new InvalidCursorHandle(); protected CursorHandle() : base(true) {} protected override bool ReleaseHandle() { SafeNativeMethods.MQCloseCursor(this.handle); return true; } public override bool IsInvalid { get { return base.IsInvalid || IsClosed; } } // A subclass needed to express InvalidHandle. The reason is that CLR notices that // ReleaseHandle requires a call to MQRT.DLL, and throws in the ctor if MQRT.DLL is not available, // even though CTOR ITSELF DOES NOT REQUIRE MQRT.DLL. // We address this by defining a NOOP ReleaseHandle sealed class InvalidCursorHandle : CursorHandle { protected override bool ReleaseHandle() { return true; } } } internal class LocatorHandle : SafeHandleZeroOrMinusOneIsInvalid { public static readonly LocatorHandle InvalidHandle = new InvalidLocatorHandle(); protected LocatorHandle() : base(true) {} protected override bool ReleaseHandle() { SafeNativeMethods.MQLocateEnd(this.handle); return true; } public override bool IsInvalid { get { return base.IsInvalid || IsClosed; } } // A subclass needed to express InvalidHandle. The reason is that CLR notices that // ReleaseHandle requires a call to MQRT.DLL, and throws in the ctor if MQRT.DLL is not available, // even though CTOR ITSELF DOES NOT REQUIRE MQRT.DLL. // We address this by defining a NOOP ReleaseHandle sealed class InvalidLocatorHandle : LocatorHandle { protected override bool ReleaseHandle() { return true; } } } internal sealed class SecurityContextHandle : SafeHandleZeroOrMinusOneIsInvalid { internal SecurityContextHandle(IntPtr existingHandle) : base(true) { SetHandle(existingHandle); } protected override bool ReleaseHandle() { SafeNativeMethods.MQFreeSecurityContext(this.handle); return true; } public override bool IsInvalid { get { return base.IsInvalid || IsClosed; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Messaging.Interop { using System; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; internal class MessageQueueHandle : SafeHandleZeroOrMinusOneIsInvalid { public static readonly MessageQueueHandle InvalidHandle = new InvalidMessageQueueHandle(); MessageQueueHandle() : base(true) {} protected override bool ReleaseHandle() { SafeNativeMethods.MQCloseQueue(this.handle); return true; } public override bool IsInvalid { get { return base.IsInvalid || IsClosed; } } // A subclass needed to express InvalidHandle. The reason is that CLR notices that // ReleaseHandle requires a call to MQRT.DLL, and throws in the ctor if MQRT.DLL is not available, // even though CTOR ITSELF DOES NOT REQUIRE MQRT.DLL. // We address this by defining a NOOP ReleaseHandle sealed class InvalidMessageQueueHandle : MessageQueueHandle { protected override bool ReleaseHandle() { return true; } } } internal class CursorHandle : SafeHandleZeroOrMinusOneIsInvalid { public static readonly CursorHandle NullHandle = new InvalidCursorHandle(); protected CursorHandle() : base(true) {} protected override bool ReleaseHandle() { SafeNativeMethods.MQCloseCursor(this.handle); return true; } public override bool IsInvalid { get { return base.IsInvalid || IsClosed; } } // A subclass needed to express InvalidHandle. The reason is that CLR notices that // ReleaseHandle requires a call to MQRT.DLL, and throws in the ctor if MQRT.DLL is not available, // even though CTOR ITSELF DOES NOT REQUIRE MQRT.DLL. // We address this by defining a NOOP ReleaseHandle sealed class InvalidCursorHandle : CursorHandle { protected override bool ReleaseHandle() { return true; } } } internal class LocatorHandle : SafeHandleZeroOrMinusOneIsInvalid { public static readonly LocatorHandle InvalidHandle = new InvalidLocatorHandle(); protected LocatorHandle() : base(true) {} protected override bool ReleaseHandle() { SafeNativeMethods.MQLocateEnd(this.handle); return true; } public override bool IsInvalid { get { return base.IsInvalid || IsClosed; } } // A subclass needed to express InvalidHandle. The reason is that CLR notices that // ReleaseHandle requires a call to MQRT.DLL, and throws in the ctor if MQRT.DLL is not available, // even though CTOR ITSELF DOES NOT REQUIRE MQRT.DLL. // We address this by defining a NOOP ReleaseHandle sealed class InvalidLocatorHandle : LocatorHandle { protected override bool ReleaseHandle() { return true; } } } internal sealed class SecurityContextHandle : SafeHandleZeroOrMinusOneIsInvalid { internal SecurityContextHandle(IntPtr existingHandle) : base(true) { SetHandle(existingHandle); } protected override bool ReleaseHandle() { SafeNativeMethods.MQFreeSecurityContext(this.handle); return true; } public override bool IsInvalid { get { return base.IsInvalid || IsClosed; } } } } // 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
- New.cs
- DecimalSumAggregationOperator.cs
- PolicyStatement.cs
- HttpInputStream.cs
- WebDisplayNameAttribute.cs
- HorizontalAlignConverter.cs
- HashCryptoHandle.cs
- Translator.cs
- SchemaContext.cs
- SystemEvents.cs
- CompositeCollection.cs
- HwndPanningFeedback.cs
- RequestNavigateEventArgs.cs
- RequestSecurityToken.cs
- PlaceHolder.cs
- _TLSstream.cs
- ToolboxDataAttribute.cs
- FacetValues.cs
- Int32Collection.cs
- MainMenu.cs
- CatalogPart.cs
- AlphaSortedEnumConverter.cs
- BuildProvider.cs
- ConfigXmlCDataSection.cs
- PointAnimationUsingKeyFrames.cs
- DesignerGeometryHelper.cs
- ClientSettingsStore.cs
- SmtpNegotiateAuthenticationModule.cs
- ConfigurationElementCollection.cs
- CalendarTable.cs
- ProxyWebPart.cs
- SamlAssertion.cs
- IdentityHolder.cs
- TextServicesManager.cs
- RecordBuilder.cs
- BulletDecorator.cs
- DataControlFieldHeaderCell.cs
- CompilerResults.cs
- SByte.cs
- CheckBox.cs
- StackBuilderSink.cs
- WeakHashtable.cs
- AutomationPatternInfo.cs
- ToolStripManager.cs
- DataGridViewLinkCell.cs
- RequestCacheManager.cs
- ObjectConverter.cs
- HitTestDrawingContextWalker.cs
- Preprocessor.cs
- ResponseBodyWriter.cs
- IsolatedStorageException.cs
- ConfigXmlElement.cs
- CmsUtils.cs
- BaseCAMarshaler.cs
- BCryptHashAlgorithm.cs
- VectorAnimationBase.cs
- DynamicDiscoveryDocument.cs
- HMACSHA256.cs
- StringResourceManager.cs
- VectorKeyFrameCollection.cs
- ETagAttribute.cs
- CommandEventArgs.cs
- DBSchemaTable.cs
- __Filters.cs
- MapPathBasedVirtualPathProvider.cs
- Canvas.cs
- SoapCodeExporter.cs
- QueryableDataSourceView.cs
- JsonXmlDataContract.cs
- CommandField.cs
- SqlXml.cs
- ProcessManager.cs
- CompilerGlobalScopeAttribute.cs
- AssemblyResourceLoader.cs
- CorrelationKeyCalculator.cs
- HtmlWindow.cs
- FileNotFoundException.cs
- ManipulationCompletedEventArgs.cs
- SrgsGrammarCompiler.cs
- RowBinding.cs
- FlatButtonAppearance.cs
- BaseParagraph.cs
- DataBinder.cs
- TabControlDesigner.cs
- validation.cs
- HttpHandler.cs
- ChunkedMemoryStream.cs
- DateTimePicker.cs
- SqlCharStream.cs
- EventOpcode.cs
- Executor.cs
- SecurityPermission.cs
- InitializationEventAttribute.cs
- SqlFunctionAttribute.cs
- HandlerBase.cs
- ToolStripItem.cs
- NamespaceList.cs
- JsonReader.cs
- DefaultTextStoreTextComposition.cs
- BrowserCapabilitiesCodeGenerator.cs