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
- TransformGroup.cs
- NestPullup.cs
- VideoDrawing.cs
- ApplicationContext.cs
- TouchDevice.cs
- WindowsServiceCredential.cs
- ExpressionSelection.cs
- ToolBarOverflowPanel.cs
- TextWriter.cs
- DataTableMapping.cs
- DesignerEditorPartChrome.cs
- LoadItemsEventArgs.cs
- ErrorView.xaml.cs
- MappedMetaModel.cs
- _SslStream.cs
- PackagingUtilities.cs
- KeyNotFoundException.cs
- MSHTMLHostUtil.cs
- ControlBuilderAttribute.cs
- DependencyObjectType.cs
- EntityDataSourceDesigner.cs
- ClaimTypeElement.cs
- SafeNativeMethods.cs
- BreadCrumbTextConverter.cs
- XmlExceptionHelper.cs
- PeoplePickerWrapper.cs
- PolyBezierSegmentFigureLogic.cs
- SortQuery.cs
- BaseParser.cs
- DesignConnection.cs
- XmlILOptimizerVisitor.cs
- RtfToXamlReader.cs
- ResourceSetExpression.cs
- sortedlist.cs
- UnsafeNativeMethods.cs
- CachedFontFace.cs
- HtmlInputHidden.cs
- SectionInformation.cs
- Monitor.cs
- EventQueueState.cs
- BinaryMessageEncodingElement.cs
- AnnotationObservableCollection.cs
- DummyDataSource.cs
- DeleteHelper.cs
- figurelength.cs
- RegexCharClass.cs
- MenuAdapter.cs
- SafeNativeMethods.cs
- CompilationLock.cs
- BrowserDefinitionCollection.cs
- CleanUpVirtualizedItemEventArgs.cs
- Transform3DGroup.cs
- SelectionHighlightInfo.cs
- RPIdentityRequirement.cs
- SemanticKeyElement.cs
- CriticalExceptions.cs
- MediaContextNotificationWindow.cs
- XPathNodeIterator.cs
- OleDbTransaction.cs
- BamlResourceSerializer.cs
- XPathNode.cs
- ContextMarshalException.cs
- EntityTypeEmitter.cs
- DocumentXPathNavigator.cs
- TreeViewAutomationPeer.cs
- ControllableStoryboardAction.cs
- SqlInfoMessageEvent.cs
- InterleavedZipPartStream.cs
- ConstNode.cs
- XmlSchemaCollection.cs
- MethodMessage.cs
- XmlConvert.cs
- DeclaredTypeElementCollection.cs
- SignatureGenerator.cs
- ExtractorMetadata.cs
- SearchForVirtualItemEventArgs.cs
- ISAPIWorkerRequest.cs
- Header.cs
- MediaPlayerState.cs
- ActivityXRefConverter.cs
- CommentEmitter.cs
- CultureInfoConverter.cs
- RectangleHotSpot.cs
- ButtonRenderer.cs
- WebBaseEventKeyComparer.cs
- DataTemplateKey.cs
- DeferrableContentConverter.cs
- ScalarType.cs
- DefaultValueAttribute.cs
- ReferenceService.cs
- FormsAuthenticationTicket.cs
- DBBindings.cs
- CustomDictionarySources.cs
- ISO2022Encoding.cs
- BitmapScalingModeValidation.cs
- SmtpTransport.cs
- UrlAuthFailedErrorFormatter.cs
- RenderingEventArgs.cs
- ModelTreeEnumerator.cs
- IFlowDocumentViewer.cs