Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / clr / src / BCL / Microsoft / Win32 / SafeHandles / Win32SafeHandles.cs / 1 / Win32SafeHandles.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // // Abstract derivations of SafeHandle designed to provide the common // functionality supporting Win32 handles. More specifically, they describe how // an invalid handle looks (for instance, some handles use -1 as an invalid // handle value, others use 0). // // Further derivations of these classes can specialise this even further (e.g. // file or registry handles). // // using System; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Security.Permissions; using System.Runtime.ConstrainedExecution; namespace Microsoft.Win32.SafeHandles { // Class of safe handle which uses 0 or -1 as an invalid handle. [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)] [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] public abstract class SafeHandleZeroOrMinusOneIsInvalid : SafeHandle { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected SafeHandleZeroOrMinusOneIsInvalid(bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { } public override bool IsInvalid { get { return handle.IsNull() || handle == new IntPtr(-1); } } } // Class of safe handle which uses only -1 as an invalid handle. [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)] [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] public abstract class SafeHandleMinusOneIsInvalid : SafeHandle { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected SafeHandleMinusOneIsInvalid(bool ownsHandle) : base(new IntPtr(-1), ownsHandle) { } public override bool IsInvalid { get { return handle == new IntPtr(-1); } } } // Class of critical handle which uses 0 or -1 as an invalid handle. [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)] [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] public abstract class CriticalHandleZeroOrMinusOneIsInvalid : CriticalHandle { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected CriticalHandleZeroOrMinusOneIsInvalid() : base(IntPtr.Zero) { } public override bool IsInvalid { get { return handle.IsNull() || handle == new IntPtr(-1); } } } // Class of critical handle which uses only -1 as an invalid handle. [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)] [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] public abstract class CriticalHandleMinusOneIsInvalid : CriticalHandle { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected CriticalHandleMinusOneIsInvalid() : base(new IntPtr(-1)) { } public override bool IsInvalid { get { return handle == new IntPtr(-1); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // // Abstract derivations of SafeHandle designed to provide the common // functionality supporting Win32 handles. More specifically, they describe how // an invalid handle looks (for instance, some handles use -1 as an invalid // handle value, others use 0). // // Further derivations of these classes can specialise this even further (e.g. // file or registry handles). // // using System; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Security.Permissions; using System.Runtime.ConstrainedExecution; namespace Microsoft.Win32.SafeHandles { // Class of safe handle which uses 0 or -1 as an invalid handle. [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)] [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] public abstract class SafeHandleZeroOrMinusOneIsInvalid : SafeHandle { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected SafeHandleZeroOrMinusOneIsInvalid(bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { } public override bool IsInvalid { get { return handle.IsNull() || handle == new IntPtr(-1); } } } // Class of safe handle which uses only -1 as an invalid handle. [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)] [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] public abstract class SafeHandleMinusOneIsInvalid : SafeHandle { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected SafeHandleMinusOneIsInvalid(bool ownsHandle) : base(new IntPtr(-1), ownsHandle) { } public override bool IsInvalid { get { return handle == new IntPtr(-1); } } } // Class of critical handle which uses 0 or -1 as an invalid handle. [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)] [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] public abstract class CriticalHandleZeroOrMinusOneIsInvalid : CriticalHandle { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected CriticalHandleZeroOrMinusOneIsInvalid() : base(IntPtr.Zero) { } public override bool IsInvalid { get { return handle.IsNull() || handle == new IntPtr(-1); } } } // Class of critical handle which uses only -1 as an invalid handle. [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode=true)] [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] public abstract class CriticalHandleMinusOneIsInvalid : CriticalHandle { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] protected CriticalHandleMinusOneIsInvalid() : base(new IntPtr(-1)) { } public override bool IsInvalid { get { return handle == new IntPtr(-1); } } } } // 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
- ToolStripRenderEventArgs.cs
- Effect.cs
- DrawingCollection.cs
- ConnectionManagementElementCollection.cs
- ClientRoleProvider.cs
- CompareValidator.cs
- BaseParser.cs
- CodeRemoveEventStatement.cs
- Constants.cs
- ExtenderProvidedPropertyAttribute.cs
- NativeMethods.cs
- ServiceHttpHandlerFactory.cs
- Package.cs
- FormatConvertedBitmap.cs
- CurrentChangedEventManager.cs
- XmlReflectionImporter.cs
- NavigatingCancelEventArgs.cs
- Certificate.cs
- DataObject.cs
- EntityDataSourceContextDisposingEventArgs.cs
- ObjectStateFormatter.cs
- SelectionWordBreaker.cs
- ToolStripPanelCell.cs
- RegexCompilationInfo.cs
- PrimitiveXmlSerializers.cs
- RelOps.cs
- HtmlEncodedRawTextWriter.cs
- RegexRunner.cs
- GenericEnumerator.cs
- CompilerGeneratedAttribute.cs
- NullRuntimeConfig.cs
- EntityDataSourceMemberPath.cs
- UnitySerializationHolder.cs
- WebPartUserCapability.cs
- WebPartCatalogAddVerb.cs
- AlgoModule.cs
- _UncName.cs
- NoneExcludedImageIndexConverter.cs
- LinearGradientBrush.cs
- FileChangesMonitor.cs
- DataControlHelper.cs
- Image.cs
- FormViewCommandEventArgs.cs
- WindowsListViewItem.cs
- ImageFormatConverter.cs
- CodeTypeDeclaration.cs
- Point.cs
- PreparingEnlistment.cs
- BaseCodeDomTreeGenerator.cs
- StringPropertyBuilder.cs
- XmlSchemaSimpleTypeRestriction.cs
- IncrementalCompileAnalyzer.cs
- RpcCryptoContext.cs
- WebPartEditVerb.cs
- SelectionUIService.cs
- StringSorter.cs
- MembershipUser.cs
- CopyOfAction.cs
- OuterGlowBitmapEffect.cs
- ProcessManager.cs
- PointF.cs
- _WinHttpWebProxyDataBuilder.cs
- LinqDataSourceDeleteEventArgs.cs
- RawMouseInputReport.cs
- ObjectDataSourceStatusEventArgs.cs
- LowerCaseStringConverter.cs
- XNodeSchemaApplier.cs
- FlowDocumentPage.cs
- ProjectionPruner.cs
- TableCell.cs
- WebPartCloseVerb.cs
- PrincipalPermission.cs
- MimePart.cs
- LambdaCompiler.Unary.cs
- UnsafeNetInfoNativeMethods.cs
- MasterPageBuildProvider.cs
- ConfigurationStrings.cs
- WebPartZone.cs
- Mouse.cs
- PackagingUtilities.cs
- ScriptManagerProxy.cs
- ClonableStack.cs
- CurrencyManager.cs
- ObjectTypeMapping.cs
- SessionStateSection.cs
- ElementHostAutomationPeer.cs
- StorageEntityTypeMapping.cs
- CodeExpressionCollection.cs
- HandlerWithFactory.cs
- StateChangeEvent.cs
- DocumentGridPage.cs
- linebase.cs
- MatrixConverter.cs
- FontStretches.cs
- SmtpReplyReaderFactory.cs
- RequestCacheEntry.cs
- EventDrivenDesigner.cs
- StaticTextPointer.cs
- CacheEntry.cs
- infer.cs