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
- QueryPageSettingsEventArgs.cs
- EventMetadata.cs
- RangeBaseAutomationPeer.cs
- ShapeTypeface.cs
- WsatConfiguration.cs
- SequentialOutput.cs
- PersistenceIOParticipant.cs
- TextWriterTraceListener.cs
- Page.cs
- StringAnimationUsingKeyFrames.cs
- ProgressBarAutomationPeer.cs
- NameValuePermission.cs
- InvalidPrinterException.cs
- ClockController.cs
- CopyAttributesAction.cs
- CodeDomDecompiler.cs
- DesignerView.Commands.cs
- SecurityImpersonationBehavior.cs
- SamlAction.cs
- FormatStringEditor.cs
- DisplayMemberTemplateSelector.cs
- RSACryptoServiceProvider.cs
- SamlAuthenticationStatement.cs
- ThousandthOfEmRealDoubles.cs
- SqlBuilder.cs
- AndCondition.cs
- LoginUtil.cs
- WindowsNonControl.cs
- SQLMembershipProvider.cs
- ConfigXmlDocument.cs
- FragmentQueryProcessor.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- QuaternionKeyFrameCollection.cs
- MemberInfoSerializationHolder.cs
- SessionIDManager.cs
- NetCodeGroup.cs
- LogWriteRestartAreaState.cs
- SoapAttributes.cs
- CachedTypeface.cs
- XPathEmptyIterator.cs
- TypeDelegator.cs
- EntityConnectionStringBuilderItem.cs
- TextEffect.cs
- CalloutQueueItem.cs
- ContentType.cs
- TransformCollection.cs
- Image.cs
- XmlCodeExporter.cs
- XmlArrayItemAttribute.cs
- HMACSHA1.cs
- OutputCacheSettings.cs
- XsltSettings.cs
- PromptBuilder.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- StronglyTypedResourceBuilder.cs
- SelectionPattern.cs
- DictionaryManager.cs
- TemplateBuilder.cs
- FontDifferentiator.cs
- TransformerInfo.cs
- XmlIlGenerator.cs
- ValidationSummary.cs
- DataControlLinkButton.cs
- ConfigurationManagerHelper.cs
- DoubleUtil.cs
- HttpCacheVary.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- FilterElement.cs
- Internal.cs
- X509ThumbprintKeyIdentifierClause.cs
- DisplayToken.cs
- Transform3DGroup.cs
- TextTreeTextNode.cs
- ContextStaticAttribute.cs
- MatrixCamera.cs
- recordstatescratchpad.cs
- WebPartConnectionsCloseVerb.cs
- WebPartConnectionCollection.cs
- ScalarType.cs
- XmlQueryCardinality.cs
- HyperLinkField.cs
- SoapSchemaImporter.cs
- MultilineStringConverter.cs
- XmlDocumentType.cs
- SchemaAttDef.cs
- LocatorPartList.cs
- WebBrowserHelper.cs
- Currency.cs
- NavigationProperty.cs
- ListBindingHelper.cs
- UshortList2.cs
- _SSPIWrapper.cs
- DebugController.cs
- AbstractSvcMapFileLoader.cs
- StringPropertyBuilder.cs
- MenuItemCollectionEditor.cs
- Point3DCollection.cs
- CollectionEditorDialog.cs
- DetailsViewPagerRow.cs
- TrustLevelCollection.cs