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
- NotifyIcon.cs
- DerivedKeySecurityToken.cs
- LexicalChunk.cs
- ECDiffieHellman.cs
- ColumnClickEvent.cs
- Fonts.cs
- FontFamilyValueSerializer.cs
- TimelineCollection.cs
- DataColumn.cs
- DispatcherExceptionEventArgs.cs
- XPathCompileException.cs
- PaperSize.cs
- MemberMemberBinding.cs
- RemotingException.cs
- Switch.cs
- cookiecontainer.cs
- RegionIterator.cs
- MenuItemCollection.cs
- CLRBindingWorker.cs
- CustomAttributeFormatException.cs
- DataGridViewLayoutData.cs
- XmlHelper.cs
- InertiaTranslationBehavior.cs
- PriorityQueue.cs
- Mouse.cs
- Attributes.cs
- DeleteIndexBinder.cs
- Merger.cs
- CategoryAttribute.cs
- QilList.cs
- IPAddress.cs
- SpoolingTask.cs
- WebPartVerbCollection.cs
- UInt64Storage.cs
- FileDataSource.cs
- ListSourceHelper.cs
- DateTimeValueSerializer.cs
- NotCondition.cs
- DrawingCollection.cs
- AttributedMetaModel.cs
- HitTestParameters.cs
- OpenFileDialog.cs
- SkipQueryOptionExpression.cs
- SyndicationSerializer.cs
- StringUtil.cs
- ResourceDictionary.cs
- HandoffBehavior.cs
- Process.cs
- ObjectDataSource.cs
- RemoteWebConfigurationHost.cs
- ConsoleKeyInfo.cs
- ConfigurationStrings.cs
- KnownBoxes.cs
- DateTime.cs
- SoapAttributeOverrides.cs
- Int32CAMarshaler.cs
- BamlBinaryReader.cs
- DropSourceBehavior.cs
- uribuilder.cs
- SliderAutomationPeer.cs
- WFItemsToSpacerVisibility.cs
- StringUtil.cs
- BaseCollection.cs
- X509RawDataKeyIdentifierClause.cs
- RightsManagementSuppressedStream.cs
- QuaternionAnimationUsingKeyFrames.cs
- SqlRowUpdatedEvent.cs
- CursorConverter.cs
- List.cs
- WebReferenceOptions.cs
- DbConnectionPoolOptions.cs
- ToolStripRendererSwitcher.cs
- RuntimeWrappedException.cs
- XDeferredAxisSource.cs
- MenuBase.cs
- PropertyInformation.cs
- MbpInfo.cs
- ValueSerializerAttribute.cs
- TypeUtils.cs
- ToolStripDropTargetManager.cs
- DataError.cs
- DependencySource.cs
- ScriptResourceHandler.cs
- DataGridPageChangedEventArgs.cs
- HtmlElement.cs
- ControlAdapter.cs
- Utils.cs
- Mappings.cs
- Emitter.cs
- CollectionConverter.cs
- Listbox.cs
- StateMachine.cs
- ClientData.cs
- LoginCancelEventArgs.cs
- LogicalMethodInfo.cs
- RecordsAffectedEventArgs.cs
- WithParamAction.cs
- FlatButtonAppearance.cs
- SvcMapFileLoader.cs
- XPathArrayIterator.cs