Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / 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;
}
}
}
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SiteMapHierarchicalDataSourceView.cs
- TypedReference.cs
- WebPartsPersonalization.cs
- input.cs
- HwndTarget.cs
- Label.cs
- CellTreeNodeVisitors.cs
- RegularExpressionValidator.cs
- FastPropertyAccessor.cs
- ListViewUpdateEventArgs.cs
- DataServiceQuery.cs
- EdmSchemaAttribute.cs
- Int32AnimationBase.cs
- HtmlWindowCollection.cs
- Pkcs7Recipient.cs
- PermissionListSet.cs
- ECDsaCng.cs
- ToolStripPanel.cs
- HistoryEventArgs.cs
- MatrixTransform3D.cs
- JpegBitmapEncoder.cs
- CommandID.cs
- ActiveXHost.cs
- ITreeGenerator.cs
- PagesChangedEventArgs.cs
- Pair.cs
- NestedContainer.cs
- SQLBoolean.cs
- SerializationException.cs
- X509CertificateClaimSet.cs
- DataSourceControl.cs
- DesignerActionHeaderItem.cs
- RegexInterpreter.cs
- ActivityTrace.cs
- log.cs
- HandleExceptionArgs.cs
- ListViewItemMouseHoverEvent.cs
- DispatcherEventArgs.cs
- PathGradientBrush.cs
- CornerRadiusConverter.cs
- _WinHttpWebProxyDataBuilder.cs
- HttpListenerRequest.cs
- TableChangeProcessor.cs
- StrokeCollection.cs
- XamlStackWriter.cs
- CodeIdentifier.cs
- DigitalSignatureProvider.cs
- CompressedStack.cs
- LoginCancelEventArgs.cs
- SrgsRuleRef.cs
- processwaithandle.cs
- AddInController.cs
- LongValidator.cs
- Part.cs
- WindowAutomationPeer.cs
- SrgsSubset.cs
- SendMailErrorEventArgs.cs
- CodeMemberProperty.cs
- Rotation3DAnimationBase.cs
- TableLayoutSettings.cs
- PresentationUIStyleResources.cs
- X500Name.cs
- SystemIPv6InterfaceProperties.cs
- ValidationSummary.cs
- Delegate.cs
- DictionaryCustomTypeDescriptor.cs
- FlowSwitch.cs
- LayoutEvent.cs
- ResourceFallbackManager.cs
- ResourceManager.cs
- ConvertEvent.cs
- ProjectionAnalyzer.cs
- BrowserCapabilitiesFactory.cs
- StringInfo.cs
- WebExceptionStatus.cs
- DtrList.cs
- ToolStripPanelRow.cs
- HttpDigestClientCredential.cs
- IsolatedStorageFileStream.cs
- MediaCommands.cs
- GeneralTransform3D.cs
- AspNetHostingPermission.cs
- hwndwrapper.cs
- HttpProcessUtility.cs
- CodeGenerator.cs
- Timer.cs
- ApplicationFileCodeDomTreeGenerator.cs
- NullableBoolConverter.cs
- RadioButtonRenderer.cs
- infer.cs
- RequestChannel.cs
- MessageSecurityOverTcp.cs
- errorpatternmatcher.cs
- KeyEvent.cs
- CharKeyFrameCollection.cs
- NamespaceDecl.cs
- SHA512Managed.cs
- SecurityUtils.cs
- CharacterString.cs
- _TransmitFileOverlappedAsyncResult.cs