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
- Wizard.cs
- EdmItemError.cs
- TextureBrush.cs
- QueueProcessor.cs
- SqlFormatter.cs
- FilterQuery.cs
- AlphabetConverter.cs
- BoundPropertyEntry.cs
- MobileComponentEditorPage.cs
- DesignerListAdapter.cs
- CodeTypeMember.cs
- DockProviderWrapper.cs
- ConnectorEditor.cs
- InstanceLockException.cs
- TreeViewItem.cs
- SimpleWebHandlerParser.cs
- SqlBooleanMismatchVisitor.cs
- RewritingValidator.cs
- DesignerInterfaces.cs
- ScriptResourceInfo.cs
- RootBrowserWindowAutomationPeer.cs
- StringStorage.cs
- XPathParser.cs
- Blend.cs
- PerCallInstanceContextProvider.cs
- SourceFilter.cs
- DrawingContext.cs
- SplitterEvent.cs
- ObjectItemAttributeAssemblyLoader.cs
- Size.cs
- XmlSchemaComplexContentRestriction.cs
- QueryableFilterUserControl.cs
- BitmapEncoder.cs
- WinEventHandler.cs
- TaiwanCalendar.cs
- GridView.cs
- DesignColumn.cs
- HttpWebResponse.cs
- StateMachineExecutionState.cs
- VirtualDirectoryMapping.cs
- DesignerRegionCollection.cs
- Thumb.cs
- GeneratedContractType.cs
- FullTextLine.cs
- SqlConnectionStringBuilder.cs
- ConfigXmlComment.cs
- _Rfc2616CacheValidators.cs
- XmlSortKey.cs
- PrivilegedConfigurationManager.cs
- BitmapEffectGroup.cs
- RefreshEventArgs.cs
- CompilerInfo.cs
- odbcmetadatacollectionnames.cs
- SessionStateModule.cs
- CompilerResults.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- OLEDB_Enum.cs
- OuterGlowBitmapEffect.cs
- TreeViewHitTestInfo.cs
- FullTextLine.cs
- ObjectViewListener.cs
- DecoderFallbackWithFailureFlag.cs
- RenderingBiasValidation.cs
- EntityDataSourceReferenceGroup.cs
- Validator.cs
- BuilderPropertyEntry.cs
- SessionState.cs
- XmlElementElementCollection.cs
- PeerCollaboration.cs
- ResourceDescriptionAttribute.cs
- TagMapInfo.cs
- TextWriter.cs
- HostingEnvironmentWrapper.cs
- CodeVariableReferenceExpression.cs
- ActiveXContainer.cs
- DataGridViewElement.cs
- BindingOperations.cs
- SmtpLoginAuthenticationModule.cs
- DataListItem.cs
- DateBoldEvent.cs
- Roles.cs
- ValueConversionAttribute.cs
- CommonDialog.cs
- StatusStrip.cs
- ReturnValue.cs
- StylusDevice.cs
- ConcurrentStack.cs
- KeyProperty.cs
- SynchronizationContext.cs
- ZipIOExtraFieldPaddingElement.cs
- LinkedList.cs
- Number.cs
- Dump.cs
- ImmutableObjectAttribute.cs
- TextServicesHost.cs
- WebUtil.cs
- NonVisualControlAttribute.cs
- SchemaLookupTable.cs
- PerSessionInstanceContextProvider.cs
- TransferRequestHandler.cs