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
- WebBrowserNavigatingEventHandler.cs
- GridViewCellAutomationPeer.cs
- ModelService.cs
- ConfigXmlSignificantWhitespace.cs
- peernodestatemanager.cs
- Single.cs
- PerformanceCounterPermissionEntryCollection.cs
- OrderedDictionary.cs
- Timer.cs
- EastAsianLunisolarCalendar.cs
- ResourcePermissionBase.cs
- EntityStoreSchemaGenerator.cs
- MessageDecoder.cs
- sitestring.cs
- DataGridItem.cs
- FixedStringLookup.cs
- ReferenceSchema.cs
- ChooseAction.cs
- DataControlReference.cs
- WindowsMenu.cs
- BitArray.cs
- DecoderFallback.cs
- MetricEntry.cs
- RichTextBoxConstants.cs
- BatchStream.cs
- BamlMapTable.cs
- LiteralControl.cs
- XmlSerializerOperationGenerator.cs
- DateTimeFormatInfo.cs
- HeaderCollection.cs
- TreeBuilder.cs
- Int16Storage.cs
- ExpressionLink.cs
- OleDbMetaDataFactory.cs
- ThicknessAnimation.cs
- SqlDataSource.cs
- safelink.cs
- ThemeableAttribute.cs
- COM2TypeInfoProcessor.cs
- ImageCodecInfo.cs
- WebServiceErrorEvent.cs
- FontFamilyConverter.cs
- ExpressionEditorAttribute.cs
- DataGridViewColumnTypePicker.cs
- InvalidOleVariantTypeException.cs
- UserControl.cs
- _ConnectionGroup.cs
- GridViewRowEventArgs.cs
- CustomExpressionEventArgs.cs
- PromptBuilder.cs
- KnownBoxes.cs
- StateItem.cs
- FormViewCommandEventArgs.cs
- storagemappingitemcollection.viewdictionary.cs
- PassportPrincipal.cs
- ExecutionEngineException.cs
- Type.cs
- QueryStatement.cs
- EditorZoneBase.cs
- TypeGeneratedEventArgs.cs
- ByteConverter.cs
- CharStorage.cs
- MaskedTextBox.cs
- AsyncStreamReader.cs
- WinCategoryAttribute.cs
- FilteredXmlReader.cs
- TraceUtility.cs
- TreeBuilder.cs
- TokenBasedSetEnumerator.cs
- sqlmetadatafactory.cs
- BlockCollection.cs
- SerialErrors.cs
- InputLangChangeEvent.cs
- CollectionContainer.cs
- RuntimeConfigLKG.cs
- TerminatorSinks.cs
- Emitter.cs
- ApplicationActivator.cs
- StoreContentChangedEventArgs.cs
- RealizationDrawingContextWalker.cs
- OdbcEnvironment.cs
- Unit.cs
- StorageScalarPropertyMapping.cs
- DataRecordInfo.cs
- XmlReflectionMember.cs
- SolidColorBrush.cs
- LifetimeServices.cs
- UndoEngine.cs
- RotateTransform3D.cs
- PropertySourceInfo.cs
- UniqueConstraint.cs
- ExportException.cs
- HotSpot.cs
- FieldNameLookup.cs
- PageCache.cs
- ImageMapEventArgs.cs
- EditingCommands.cs
- UriParserTemplates.cs
- CroppedBitmap.cs
- OdbcException.cs