Code:
/ FX-1434 / FX-1434 / 1.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
- TrackingDataItem.cs
- ObjectToModelValueConverter.cs
- HMACRIPEMD160.cs
- SafeProcessHandle.cs
- HttpDictionary.cs
- DropShadowEffect.cs
- TimeoutException.cs
- XmlSignatureProperties.cs
- AssignDesigner.xaml.cs
- XamlReaderHelper.cs
- XmlDataSourceNodeDescriptor.cs
- WSSecureConversation.cs
- SecurityCriticalDataForSet.cs
- XmlSerializerAssemblyAttribute.cs
- ResourceManagerWrapper.cs
- SegmentInfo.cs
- HandlerBase.cs
- PrinterSettings.cs
- ColorConverter.cs
- DataTableReader.cs
- QilExpression.cs
- ScrollViewerAutomationPeer.cs
- Journaling.cs
- OrderedEnumerableRowCollection.cs
- Location.cs
- CallContext.cs
- NumberFormatInfo.cs
- PolicyImporterElementCollection.cs
- BuilderInfo.cs
- PropertyDescriptorCollection.cs
- SqlParameterCollection.cs
- FilterEventArgs.cs
- PageWrapper.cs
- TableItemProviderWrapper.cs
- ParseHttpDate.cs
- UrlAuthorizationModule.cs
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- PropertyValueUIItem.cs
- StatusBarItemAutomationPeer.cs
- RenderDataDrawingContext.cs
- RegexCompilationInfo.cs
- XmlParserContext.cs
- GestureRecognizer.cs
- OuterGlowBitmapEffect.cs
- _SpnDictionary.cs
- DocumentAutomationPeer.cs
- ThicknessAnimationUsingKeyFrames.cs
- DynamicExpression.cs
- MiniConstructorInfo.cs
- SqlDataRecord.cs
- Currency.cs
- NGCSerializer.cs
- FolderLevelBuildProviderAppliesToAttribute.cs
- NotifyParentPropertyAttribute.cs
- ModuleElement.cs
- StringWriter.cs
- XamlWriter.cs
- FormattedText.cs
- TextRangeEditLists.cs
- ItemCollection.cs
- OperationCanceledException.cs
- TextTreeNode.cs
- TextLine.cs
- PropertyGeneratedEventArgs.cs
- BehaviorService.cs
- MD5Cng.cs
- HttpServerUtilityWrapper.cs
- contentDescriptor.cs
- WebServiceFaultDesigner.cs
- SingleKeyFrameCollection.cs
- AsymmetricKeyExchangeFormatter.cs
- WebRequest.cs
- DataKeyPropertyAttribute.cs
- UIElementAutomationPeer.cs
- PinnedBufferMemoryStream.cs
- ExtractorMetadata.cs
- WebHttpEndpointElement.cs
- CommonProperties.cs
- ComponentResourceKey.cs
- DataGridColumn.cs
- KeyValuePairs.cs
- ResXFileRef.cs
- TraceListeners.cs
- CommandID.cs
- ItemsChangedEventArgs.cs
- RouteItem.cs
- TaskDesigner.cs
- Utils.cs
- FontFamilyValueSerializer.cs
- MultipleCopiesCollection.cs
- IndexedWhereQueryOperator.cs
- NativeMethods.cs
- MenuItemBindingCollection.cs
- TdsParserSessionPool.cs
- CellTreeNode.cs
- X509SubjectKeyIdentifierClause.cs
- EdgeModeValidation.cs
- ModulesEntry.cs
- LogSwitch.cs
- HwndStylusInputProvider.cs