Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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); } } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ArrangedElementCollection.cs
- LinqExpressionNormalizer.cs
- InheritanceAttribute.cs
- UndoManager.cs
- RestClientProxyHandler.cs
- DataGridViewRowStateChangedEventArgs.cs
- ScrollEventArgs.cs
- StrongNameIdentityPermission.cs
- PopupRoot.cs
- StringValidatorAttribute.cs
- sqlser.cs
- DataGridItemEventArgs.cs
- CodeMemberProperty.cs
- ConfigurationPropertyCollection.cs
- UTF8Encoding.cs
- HttpHandlerActionCollection.cs
- Message.cs
- DesignTimeTemplateParser.cs
- DatePickerDateValidationErrorEventArgs.cs
- SyndicationContent.cs
- Int32CAMarshaler.cs
- MarkerProperties.cs
- RijndaelManaged.cs
- ContourSegment.cs
- DataRecordInternal.cs
- TextEditorSelection.cs
- basenumberconverter.cs
- Rights.cs
- VideoDrawing.cs
- CustomPopupPlacement.cs
- CreateUserWizardStep.cs
- TrackingMemoryStreamFactory.cs
- ProcessThreadCollection.cs
- WpfWebRequestHelper.cs
- XPathNavigator.cs
- SiteMapDataSource.cs
- EntityDataSourceState.cs
- InfoCardKeyedHashAlgorithm.cs
- OutputCacheSection.cs
- TagElement.cs
- FixedSOMElement.cs
- SelectedGridItemChangedEvent.cs
- EventsTab.cs
- QueryParameter.cs
- BitStream.cs
- BamlLocalizer.cs
- TableCellCollection.cs
- SystemInformation.cs
- _LocalDataStoreMgr.cs
- DeferredTextReference.cs
- XmlElementElement.cs
- IntranetCredentialPolicy.cs
- CheckableControlBaseAdapter.cs
- Ray3DHitTestResult.cs
- IntegrationExceptionEventArgs.cs
- CodeSnippetTypeMember.cs
- DataViewSettingCollection.cs
- DatatypeImplementation.cs
- _ContextAwareResult.cs
- EmptyCollection.cs
- SHA384Managed.cs
- BorderGapMaskConverter.cs
- ThreadAbortException.cs
- JsonFormatReaderGenerator.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- CancellationTokenRegistration.cs
- Control.cs
- RichTextBoxContextMenu.cs
- DPCustomTypeDescriptor.cs
- PeerInputChannel.cs
- MaskInputRejectedEventArgs.cs
- TabletDevice.cs
- SettingsPropertyValue.cs
- ObjectDataSourceEventArgs.cs
- DataKeyCollection.cs
- GridViewEditEventArgs.cs
- SqlTypeConverter.cs
- BoundColumn.cs
- DataGridViewColumn.cs
- TableDetailsCollection.cs
- ResourceReferenceExpression.cs
- FormsAuthenticationEventArgs.cs
- Stacktrace.cs
- UnaryExpression.cs
- ThousandthOfEmRealDoubles.cs
- ISCIIEncoding.cs
- ModelItemKeyValuePair.cs
- NavigationWindowAutomationPeer.cs
- AbandonedMutexException.cs
- ProxyWebPartManagerDesigner.cs
- GPStream.cs
- arc.cs
- PageTheme.cs
- Int64Converter.cs
- SqlResolver.cs
- Vector3D.cs
- TripleDESCryptoServiceProvider.cs
- DataGridViewTextBoxColumn.cs
- CodeBlockBuilder.cs
- ModuleConfigurationInfo.cs