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
- GraphicsContainer.cs
- IApplicationTrustManager.cs
- XmlMemberMapping.cs
- Point3DCollection.cs
- ListItemCollection.cs
- ProviderSettings.cs
- TemplatedEditableDesignerRegion.cs
- Util.cs
- RotateTransform.cs
- SortDescription.cs
- SiteMapPath.cs
- HtmlProps.cs
- WriteableBitmap.cs
- wgx_exports.cs
- ToolStripContentPanelRenderEventArgs.cs
- LogLogRecordHeader.cs
- DataRow.cs
- FaultDescription.cs
- StructuralCache.cs
- ImageKeyConverter.cs
- SelectorItemAutomationPeer.cs
- Shape.cs
- SecurityBindingElementImporter.cs
- SectionVisual.cs
- SqlProviderManifest.cs
- TransformGroup.cs
- IResourceProvider.cs
- LineProperties.cs
- URL.cs
- EventLogEntryCollection.cs
- ControlCollection.cs
- XPathDocumentIterator.cs
- EvidenceTypeDescriptor.cs
- XmlAttributeAttribute.cs
- UserControlCodeDomTreeGenerator.cs
- _LocalDataStoreMgr.cs
- IsolatedStorageFilePermission.cs
- FormattedText.cs
- MetadataArtifactLoader.cs
- GradientSpreadMethodValidation.cs
- ProgressBarAutomationPeer.cs
- ServiceInstanceProvider.cs
- MasterPage.cs
- OpenCollectionAsyncResult.cs
- Int16Converter.cs
- CodeObject.cs
- WindowHideOrCloseTracker.cs
- PolicyException.cs
- EditorBrowsableAttribute.cs
- ReaderOutput.cs
- PeerNameRecord.cs
- ValueChangedEventManager.cs
- RenderContext.cs
- ByeMessageApril2005.cs
- ListBox.cs
- ResourceType.cs
- PerfService.cs
- ParamArrayAttribute.cs
- ListQueryResults.cs
- BulletedList.cs
- Grammar.cs
- ProcessThreadCollection.cs
- ToolStripLabel.cs
- MemberInfoSerializationHolder.cs
- Int16KeyFrameCollection.cs
- ExpressionHelper.cs
- ProcessHostConfigUtils.cs
- BufferBuilder.cs
- Activator.cs
- ApplicationContext.cs
- securestring.cs
- MessageQueueEnumerator.cs
- LOSFormatter.cs
- Transform3D.cs
- RSAProtectedConfigurationProvider.cs
- PathSegmentCollection.cs
- SortAction.cs
- ContentTypeSettingClientMessageFormatter.cs
- Stack.cs
- SecurityHeader.cs
- Parser.cs
- ScriptingRoleServiceSection.cs
- WindowsSolidBrush.cs
- MenuItemStyle.cs
- UserControlParser.cs
- SchemaImporterExtensionsSection.cs
- IntegerValidator.cs
- WSAddressing10ProblemHeaderQNameFault.cs
- FixedSOMElement.cs
- CompositeKey.cs
- SplineKeyFrames.cs
- TypeConverter.cs
- TraceListeners.cs
- Zone.cs
- DoubleUtil.cs
- IpcChannelHelper.cs
- WorkflowInstanceProxy.cs
- DesignerVerb.cs
- filewebresponse.cs
- EditorPartCollection.cs