Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- PasswordBoxAutomationPeer.cs
- OdbcCommandBuilder.cs
- GridViewDeletedEventArgs.cs
- ExceptionHelpers.cs
- QilGeneratorEnv.cs
- EntityClassGenerator.cs
- ToolStripContextMenu.cs
- SecUtil.cs
- Vector3DConverter.cs
- FilteredReadOnlyMetadataCollection.cs
- AsymmetricSignatureFormatter.cs
- SerializerDescriptor.cs
- DataServiceClientException.cs
- XmlHierarchyData.cs
- BindingNavigator.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- BrushMappingModeValidation.cs
- SerialErrors.cs
- MultipleViewPattern.cs
- SrgsElement.cs
- StylusLogic.cs
- DesignConnection.cs
- CurrencyWrapper.cs
- SerialStream.cs
- Panel.cs
- unsafenativemethodstextservices.cs
- IntSecurity.cs
- DataTablePropertyDescriptor.cs
- XmlStringTable.cs
- PresentationTraceSources.cs
- XmlRawWriter.cs
- SplashScreen.cs
- AccessViolationException.cs
- BypassElementCollection.cs
- ListMarkerSourceInfo.cs
- MailAddressParser.cs
- WebPartTransformerCollection.cs
- XmlSchemaCompilationSettings.cs
- LinqDataSourceEditData.cs
- Int64AnimationUsingKeyFrames.cs
- Graphics.cs
- AsyncPostBackTrigger.cs
- EntityClientCacheEntry.cs
- EntityDataSourceConfigureObjectContext.cs
- _NegotiateClient.cs
- EnglishPluralizationService.cs
- SystemInformation.cs
- SymbolPair.cs
- RelatedCurrencyManager.cs
- XmlStreamStore.cs
- MsmqIntegrationProcessProtocolHandler.cs
- StringDictionary.cs
- UriScheme.cs
- ClientConfigurationHost.cs
- CompressedStack.cs
- JavaScriptSerializer.cs
- XamlPathDataSerializer.cs
- RoutedEventHandlerInfo.cs
- MouseButton.cs
- ConcurrentStack.cs
- FindResponse.cs
- PeerCustomResolverBindingElement.cs
- RequestBringIntoViewEventArgs.cs
- QueryableFilterRepeater.cs
- ExpressionPrefixAttribute.cs
- ButtonPopupAdapter.cs
- WindowsListViewItemCheckBox.cs
- ListViewPagedDataSource.cs
- MemoryRecordBuffer.cs
- ActionFrame.cs
- Matrix3DStack.cs
- ThumbButtonInfoCollection.cs
- Configuration.cs
- Padding.cs
- DrawingContext.cs
- ConfigurationManagerInternalFactory.cs
- ExtensibleClassFactory.cs
- SolidColorBrush.cs
- WindowInteractionStateTracker.cs
- AssemblyName.cs
- SingleStorage.cs
- InputLangChangeEvent.cs
- NativeMethods.cs
- RegexBoyerMoore.cs
- ToolBarButton.cs
- contentDescriptor.cs
- TextWriterEngine.cs
- XPathDescendantIterator.cs
- DataObjectSettingDataEventArgs.cs
- DesignerActionList.cs
- EraserBehavior.cs
- Exceptions.cs
- LogSwitch.cs
- _CommandStream.cs
- WebReferencesBuildProvider.cs
- AssemblyCache.cs
- ConfigurationPropertyAttribute.cs
- CodeTypeReferenceExpression.cs
- SafeFileMappingHandle.cs
- LinqDataSourceInsertEventArgs.cs