Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- MouseButton.cs
- Expr.cs
- SmtpAuthenticationManager.cs
- Mappings.cs
- ProvidersHelper.cs
- HuffmanTree.cs
- DateTimeSerializationSection.cs
- TextRange.cs
- ComponentDispatcher.cs
- SchemaConstraints.cs
- ResXFileRef.cs
- MailAddressCollection.cs
- MsmqException.cs
- KnowledgeBase.cs
- ObjectDataSourceDisposingEventArgs.cs
- SafeRightsManagementSessionHandle.cs
- XmlSchemaSimpleTypeRestriction.cs
- x509utils.cs
- MappingModelBuildProvider.cs
- MessageBox.cs
- OracleRowUpdatedEventArgs.cs
- SemanticValue.cs
- CollectionChangeEventArgs.cs
- FacetDescriptionElement.cs
- SimpleRecyclingCache.cs
- MemoryMappedView.cs
- ListCollectionView.cs
- TdsEnums.cs
- TcpTransportSecurityElement.cs
- ToolStripDropTargetManager.cs
- ActivityWithResultValueSerializer.cs
- ToolStripDropDownClosingEventArgs.cs
- ScrollViewerAutomationPeer.cs
- XmlSchemaSimpleType.cs
- FixedTextPointer.cs
- TextReturnReader.cs
- FlowLayoutPanel.cs
- RequestCachingSection.cs
- AcceleratedTokenProviderState.cs
- HtmlElement.cs
- ValidationError.cs
- ControlsConfig.cs
- DataServiceProviderMethods.cs
- WebResourceUtil.cs
- SafeLibraryHandle.cs
- SponsorHelper.cs
- BypassElementCollection.cs
- XmlSchemaAttributeGroupRef.cs
- NestPullup.cs
- Visitor.cs
- ErrorFormatterPage.cs
- PropertyItemInternal.cs
- SeverityFilter.cs
- Script.cs
- SqlDataSourceEnumerator.cs
- WebSysDescriptionAttribute.cs
- SystemKeyConverter.cs
- ClientScriptManager.cs
- Manipulation.cs
- Win32KeyboardDevice.cs
- SolidColorBrush.cs
- ADMembershipProvider.cs
- DrawingGroupDrawingContext.cs
- DiscoveryEndpointValidator.cs
- MessagingDescriptionAttribute.cs
- DateTimeConverter2.cs
- MobileErrorInfo.cs
- MulticastOption.cs
- TemplateControlBuildProvider.cs
- columnmapkeybuilder.cs
- TextEditorCharacters.cs
- TaskScheduler.cs
- TreeViewTemplateSelector.cs
- AppSecurityManager.cs
- ToolStripDropDownButton.cs
- ContextMenuService.cs
- KnownBoxes.cs
- FileLoadException.cs
- GridView.cs
- ObservableDictionary.cs
- XmlHierarchicalEnumerable.cs
- NavigationProperty.cs
- CharKeyFrameCollection.cs
- FileResponseElement.cs
- HealthMonitoringSectionHelper.cs
- SQLBinary.cs
- selecteditemcollection.cs
- VideoDrawing.cs
- PackageDigitalSignatureManager.cs
- SQlBooleanStorage.cs
- ValueConversionAttribute.cs
- RtType.cs
- XmlArrayAttribute.cs
- PriorityBinding.cs
- DBConnection.cs
- CollectionType.cs
- BitArray.cs
- ClientRolePrincipal.cs
- SimpleTextLine.cs
- LazyLoadBehavior.cs