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
- AsyncContentLoadedEventArgs.cs
- SystemPens.cs
- ACL.cs
- TypedLocationWrapper.cs
- ControlEvent.cs
- HttpProfileBase.cs
- Clock.cs
- WorkItem.cs
- IntSecurity.cs
- XmlQueryStaticData.cs
- DoubleCollectionValueSerializer.cs
- DispatcherEventArgs.cs
- DynamicUpdateCommand.cs
- DrawingCollection.cs
- ContainerSelectorGlyph.cs
- DoubleAnimationUsingKeyFrames.cs
- WinHttpWebProxyFinder.cs
- EpmCustomContentDeSerializer.cs
- DynamicRendererThreadManager.cs
- VirtualPath.cs
- SspiNegotiationTokenAuthenticatorState.cs
- CodeVariableDeclarationStatement.cs
- MimeAnyImporter.cs
- OpacityConverter.cs
- TemplatedMailWebEventProvider.cs
- StylusPoint.cs
- TextBox.cs
- NameValueCollection.cs
- URL.cs
- SelectionRange.cs
- StatusStrip.cs
- PackageStore.cs
- BitmapEffectGeneralTransform.cs
- XPathDocumentIterator.cs
- DataSourceProvider.cs
- ContextStack.cs
- DataBindingCollectionConverter.cs
- EdmScalarPropertyAttribute.cs
- ThicknessAnimation.cs
- ExpressionNormalizer.cs
- TextBox.cs
- RsaSecurityTokenAuthenticator.cs
- Optimizer.cs
- SafeRegistryHandle.cs
- DataKeyCollection.cs
- WebPartTransformerCollection.cs
- FileInfo.cs
- DSACryptoServiceProvider.cs
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- TakeOrSkipQueryOperator.cs
- ADConnectionHelper.cs
- InputMethodStateChangeEventArgs.cs
- RecognizerInfo.cs
- ModelTreeEnumerator.cs
- SafeViewOfFileHandle.cs
- FormsAuthenticationUser.cs
- XmlNamespaceDeclarationsAttribute.cs
- DataGridViewDataErrorEventArgs.cs
- MarkupExtensionParser.cs
- HtmlTextArea.cs
- Stack.cs
- SByteConverter.cs
- FileNotFoundException.cs
- DetailsViewDeleteEventArgs.cs
- SwitchElementsCollection.cs
- CheckBox.cs
- UrlPath.cs
- GridViewCellAutomationPeer.cs
- MgmtResManager.cs
- SymmetricSecurityBindingElement.cs
- FieldToken.cs
- DependencyObjectCodeDomSerializer.cs
- ChameleonKey.cs
- ConcurrencyMode.cs
- AssertUtility.cs
- XmlSchemaAnnotated.cs
- TempFiles.cs
- ScrollItemPattern.cs
- xsdvalidator.cs
- Border.cs
- BitmapFrameDecode.cs
- UTF32Encoding.cs
- ThreadStateException.cs
- QilLiteral.cs
- HttpContext.cs
- StyleTypedPropertyAttribute.cs
- RoutedEvent.cs
- HtmlForm.cs
- RichTextBox.cs
- XmlTypeAttribute.cs
- MetadataUtil.cs
- DrawingBrush.cs
- util.cs
- LocalBuilder.cs
- SetMemberBinder.cs
- MarkupCompiler.cs
- BitmapEffectGroup.cs
- XmlDictionaryReader.cs
- BaseCAMarshaler.cs
- XmlUnspecifiedAttribute.cs