Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- ReturnValue.cs
- BindingParameterCollection.cs
- SqlFormatter.cs
- Vector3DAnimation.cs
- InvalidOleVariantTypeException.cs
- ValueOfAction.cs
- Comparer.cs
- SystemMulticastIPAddressInformation.cs
- ExceptionHelpers.cs
- XmlParserContext.cs
- WebBrowser.cs
- InputGestureCollection.cs
- CqlWriter.cs
- OdbcCommand.cs
- ModulesEntry.cs
- StringInfo.cs
- DataGridDetailsPresenter.cs
- PointCollection.cs
- CodeTypeDeclaration.cs
- DataGridColumnCollectionEditor.cs
- CodeTypeReferenceCollection.cs
- compensatingcollection.cs
- DbDeleteCommandTree.cs
- NameValueCache.cs
- WebPartVerbCollection.cs
- XComponentModel.cs
- SafePipeHandle.cs
- TextEffect.cs
- GlyphRunDrawing.cs
- WmpBitmapEncoder.cs
- MD5CryptoServiceProvider.cs
- Part.cs
- HealthMonitoringSectionHelper.cs
- DrawingContextDrawingContextWalker.cs
- ImageCodecInfoPrivate.cs
- SecurityContext.cs
- TextViewSelectionProcessor.cs
- SqlReorderer.cs
- PackageFilter.cs
- XmlSchemaValidator.cs
- log.cs
- FontFamilyValueSerializer.cs
- DataColumnCollection.cs
- RadioButtonStandardAdapter.cs
- DateTimeFormatInfo.cs
- XmlSchemaSimpleTypeUnion.cs
- MergePropertyDescriptor.cs
- BinaryCommonClasses.cs
- WorkflowQueueInfo.cs
- PassportAuthenticationEventArgs.cs
- ComponentDispatcher.cs
- HtmlSelect.cs
- RbTree.cs
- ClientRolePrincipal.cs
- File.cs
- SyndicationItem.cs
- InputScopeAttribute.cs
- RawStylusInput.cs
- DrawingContextWalker.cs
- SapiRecognizer.cs
- ImageSourceConverter.cs
- OutputCacheProfile.cs
- GenericEnumConverter.cs
- DataGridViewLinkCell.cs
- PixelFormat.cs
- LowerCaseStringConverter.cs
- PropertyItemInternal.cs
- DisableDpiAwarenessAttribute.cs
- SqlFormatter.cs
- PropertySegmentSerializer.cs
- PresentationAppDomainManager.cs
- Int64KeyFrameCollection.cs
- AuthenticationConfig.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- StreamGeometry.cs
- InfoCardRSAPKCS1SignatureDeformatter.cs
- TextMarkerSource.cs
- LabelAutomationPeer.cs
- SqlNamer.cs
- ListViewPagedDataSource.cs
- BinaryKeyIdentifierClause.cs
- AutomationPropertyInfo.cs
- ScrollBar.cs
- NegotiateStream.cs
- SignatureToken.cs
- ConfigurationSectionGroupCollection.cs
- WebServiceReceiveDesigner.cs
- WindowsToolbar.cs
- InvalidCastException.cs
- CipherData.cs
- ColorTransformHelper.cs
- ExeConfigurationFileMap.cs
- SrgsItemList.cs
- ListComponentEditor.cs
- ToolStripItemCollection.cs
- HtmlProps.cs
- MemberCollection.cs
- COSERVERINFO.cs
- BrowserCapabilitiesFactoryBase.cs
- ComponentConverter.cs