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 / SafeRegistryHandle.cs / 1 / SafeRegistryHandle.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: SafeRegistryHandle ** ** ** A wrapper for registry handles ** ** ===========================================================*/ using System; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; namespace Microsoft.Win32.SafeHandles { internal sealed class SafeRegistryHandle : SafeHandleZeroOrMinusOneIsInvalid { // Note: Officially -1 is the recommended invalid handle value for // registry keys, but we'll also get back 0 as an invalid handle from // RegOpenKeyEx. [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] internal SafeRegistryHandle() : base(true) {} [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] internal SafeRegistryHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) { SetHandle(preexistingHandle); } [DllImport(Win32Native.ADVAPI32), SuppressUnmanagedCodeSecurity, ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] private static extern int RegCloseKey(IntPtr hKey); override protected bool ReleaseHandle() { // Returns a Win32 error code, 0 for success int r = RegCloseKey(handle); return r == 0; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: SafeRegistryHandle ** ** ** A wrapper for registry handles ** ** ===========================================================*/ using System; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; namespace Microsoft.Win32.SafeHandles { internal sealed class SafeRegistryHandle : SafeHandleZeroOrMinusOneIsInvalid { // Note: Officially -1 is the recommended invalid handle value for // registry keys, but we'll also get back 0 as an invalid handle from // RegOpenKeyEx. [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] internal SafeRegistryHandle() : base(true) {} [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)] internal SafeRegistryHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) { SetHandle(preexistingHandle); } [DllImport(Win32Native.ADVAPI32), SuppressUnmanagedCodeSecurity, ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] private static extern int RegCloseKey(IntPtr hKey); override protected bool ReleaseHandle() { // Returns a Win32 error code, 0 for success int r = RegCloseKey(handle); return r == 0; } } } // 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
- RoleGroupCollectionEditor.cs
- RenderCapability.cs
- Gdiplus.cs
- SQLRoleProvider.cs
- PagedControl.cs
- Model3DGroup.cs
- PersonalizationState.cs
- StrongName.cs
- RegexFCD.cs
- GroupBox.cs
- FillRuleValidation.cs
- MimeBasePart.cs
- _NetworkingPerfCounters.cs
- SelectionProviderWrapper.cs
- DataFieldConverter.cs
- SystemFonts.cs
- SerializationTrace.cs
- _IPv4Address.cs
- WebPartConnectionsCloseVerb.cs
- FolderLevelBuildProviderAppliesToAttribute.cs
- LongValidator.cs
- SqlConnection.cs
- X509Chain.cs
- ConstraintStruct.cs
- HtmlButton.cs
- DispatcherSynchronizationContext.cs
- MultiSelectRootGridEntry.cs
- StructuredTypeEmitter.cs
- ByteStack.cs
- DrawingGroupDrawingContext.cs
- DurableInstanceProvider.cs
- GridViewRowEventArgs.cs
- XmlSchemaAttributeGroup.cs
- ExclusiveHandle.cs
- Label.cs
- BaseDataListPage.cs
- InlineObject.cs
- GenericIdentity.cs
- Point3DCollection.cs
- IntSecurity.cs
- HttpVersion.cs
- LowerCaseStringConverter.cs
- EventRecord.cs
- DiscreteKeyFrames.cs
- WeakHashtable.cs
- NavigateEvent.cs
- Optimizer.cs
- SoapObjectInfo.cs
- FilterableData.cs
- UIHelper.cs
- PagesSection.cs
- TimeSpanParse.cs
- HealthMonitoringSectionHelper.cs
- WindowsEditBox.cs
- ConfigXmlAttribute.cs
- CodeDirectoryCompiler.cs
- PageAsyncTaskManager.cs
- PartialTrustVisibleAssembliesSection.cs
- ButtonDesigner.cs
- BufferedGraphicsManager.cs
- URLAttribute.cs
- SpecialNameAttribute.cs
- WebPartDeleteVerb.cs
- NameValuePair.cs
- TextDecorationCollection.cs
- QuadraticBezierSegment.cs
- BulletedList.cs
- HtmlFormWrapper.cs
- basecomparevalidator.cs
- PersonalizationStateQuery.cs
- NameNode.cs
- PackagePart.cs
- EncoderExceptionFallback.cs
- DBConcurrencyException.cs
- BooleanKeyFrameCollection.cs
- DoubleLinkListEnumerator.cs
- QualifiedCellIdBoolean.cs
- Package.cs
- ReflectionPermission.cs
- AsyncPostBackTrigger.cs
- SecurityHeader.cs
- PenThreadPool.cs
- RelationshipNavigation.cs
- WebPartMinimizeVerb.cs
- LogicalChannel.cs
- ErrorFormatter.cs
- ByteRangeDownloader.cs
- MenuItem.cs
- BooleanToVisibilityConverter.cs
- ISAPIRuntime.cs
- FileVersionInfo.cs
- DependencyObjectProvider.cs
- IDQuery.cs
- CheckBoxStandardAdapter.cs
- AttributeQuery.cs
- PathParser.cs
- GridViewColumnHeader.cs
- ReachVisualSerializer.cs
- VScrollProperties.cs
- SystemIPv6InterfaceProperties.cs