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
- ObjectReferenceStack.cs
- Native.cs
- basenumberconverter.cs
- Int64AnimationUsingKeyFrames.cs
- EntityDataSourceContainerNameItem.cs
- ADMembershipUser.cs
- PropertyNames.cs
- LayoutTable.cs
- XmlNode.cs
- LayoutTable.cs
- FixedSOMContainer.cs
- ExpressionEditorAttribute.cs
- ManifestResourceInfo.cs
- NodeLabelEditEvent.cs
- AsyncPostBackErrorEventArgs.cs
- UndirectedGraph.cs
- DeviceContexts.cs
- ContentDesigner.cs
- COM2TypeInfoProcessor.cs
- ViewStateChangedEventArgs.cs
- QueryContinueDragEvent.cs
- Calendar.cs
- SolidColorBrush.cs
- LocalValueEnumerator.cs
- ByValueEqualityComparer.cs
- Vector3D.cs
- SqlError.cs
- RawStylusSystemGestureInputReport.cs
- RNGCryptoServiceProvider.cs
- EditorPartChrome.cs
- SQLBytes.cs
- TextRangeEdit.cs
- ToolBarButtonClickEvent.cs
- ToolboxService.cs
- GridViewHeaderRowPresenter.cs
- DataColumnPropertyDescriptor.cs
- AutomationElementCollection.cs
- TabPanel.cs
- MimeXmlImporter.cs
- BindingSourceDesigner.cs
- EntryPointNotFoundException.cs
- AvtEvent.cs
- HMACSHA512.cs
- SplitterCancelEvent.cs
- PassportIdentity.cs
- BinaryCommonClasses.cs
- SystemInfo.cs
- LedgerEntryCollection.cs
- PropertyPath.cs
- XmlQualifiedNameTest.cs
- OleDbConnectionInternal.cs
- ApplicationBuildProvider.cs
- RemotingSurrogateSelector.cs
- uribuilder.cs
- QueuePropertyVariants.cs
- EnumBuilder.cs
- HwndSource.cs
- GlyphRunDrawing.cs
- ListBoxChrome.cs
- ProviderSettingsCollection.cs
- SchemaTableOptionalColumn.cs
- PreviewKeyDownEventArgs.cs
- ExpandCollapseProviderWrapper.cs
- RectConverter.cs
- DiscriminatorMap.cs
- PatternMatcher.cs
- AttributeUsageAttribute.cs
- PieceDirectory.cs
- ThicknessAnimationUsingKeyFrames.cs
- EmbeddedMailObject.cs
- CurrentChangedEventManager.cs
- ValueChangedEventManager.cs
- MimeParameters.cs
- ClientSettingsProvider.cs
- NavigationPropertyEmitter.cs
- SubstitutionResponseElement.cs
- COM2TypeInfoProcessor.cs
- SecureUICommand.cs
- RoutedEvent.cs
- BufferedGraphics.cs
- Color.cs
- Int16Converter.cs
- Membership.cs
- TableLayoutRowStyleCollection.cs
- ProxyManager.cs
- CardSpaceSelector.cs
- RestrictedTransactionalPackage.cs
- DataGridViewControlCollection.cs
- FileSystemEventArgs.cs
- Compiler.cs
- WebPart.cs
- SafeThreadHandle.cs
- HttpListenerRequestUriBuilder.cs
- DesignerActionListCollection.cs
- messageonlyhwndwrapper.cs
- DateTimeOffsetStorage.cs
- DbMetaDataCollectionNames.cs
- HttpRequestTraceRecord.cs
- ImageCodecInfoPrivate.cs
- HostSecurityManager.cs