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
- StorageTypeMapping.cs
- ObjectReaderCompiler.cs
- StructuralCache.cs
- AssemblyHash.cs
- DiffuseMaterial.cs
- ButtonBaseAdapter.cs
- DefaultParameterValueAttribute.cs
- CompiledELinqQueryState.cs
- StrokeDescriptor.cs
- diagnosticsswitches.cs
- TableLayoutSettingsTypeConverter.cs
- ProfileManager.cs
- ReferenceCountedObject.cs
- EnumValAlphaComparer.cs
- CorrelationManager.cs
- EventKeyword.cs
- PrefixQName.cs
- InvalidOperationException.cs
- IsolatedStoragePermission.cs
- SortedDictionary.cs
- LinqDataView.cs
- CalendarTable.cs
- TypeDescriptionProvider.cs
- OrderByLifter.cs
- TableDetailsRow.cs
- TableLayoutRowStyleCollection.cs
- DateTimeUtil.cs
- ArrayTypeMismatchException.cs
- MetafileHeaderWmf.cs
- DetailsViewInsertEventArgs.cs
- InternalsVisibleToAttribute.cs
- MachineKeySection.cs
- UniqueContractNameValidationBehavior.cs
- MarshalByRefObject.cs
- EventItfInfo.cs
- DrawTreeNodeEventArgs.cs
- ActivityTypeDesigner.xaml.cs
- BuildProvider.cs
- TTSEngineTypes.cs
- MaskedTextBoxTextEditorDropDown.cs
- FacetEnabledSchemaElement.cs
- CodeGen.cs
- FlowDocument.cs
- Int32RectValueSerializer.cs
- ChildChangedEventArgs.cs
- TextRangeBase.cs
- MemberMemberBinding.cs
- CompilerResults.cs
- SupportingTokenDuplexChannel.cs
- ConfigXmlReader.cs
- ParseNumbers.cs
- ListControlStringCollectionEditor.cs
- TrustLevel.cs
- BindingValueChangedEventArgs.cs
- IconConverter.cs
- Misc.cs
- FloaterBaseParagraph.cs
- SolidBrush.cs
- StatusBar.cs
- SpecialNameAttribute.cs
- AudioBase.cs
- MultipartContentParser.cs
- SecuritySessionFilter.cs
- DesignerHierarchicalDataSourceView.cs
- NullExtension.cs
- FormClosedEvent.cs
- RegexTree.cs
- EventLogEntryCollection.cs
- Panel.cs
- XmlSchemaInclude.cs
- JsonCollectionDataContract.cs
- RegexMatchCollection.cs
- MetadataWorkspace.cs
- ToolStripOverflow.cs
- ContextQuery.cs
- WorkflowRuntimeServiceElement.cs
- ChannelBase.cs
- HandleRef.cs
- DispatcherFrame.cs
- As.cs
- WebZone.cs
- DataRelationPropertyDescriptor.cs
- AutomationPeer.cs
- TraceContextRecord.cs
- AmbientLight.cs
- HtmlShimManager.cs
- WebPartZoneBase.cs
- ParagraphResult.cs
- TransformerInfoCollection.cs
- MouseGesture.cs
- PipelineModuleStepContainer.cs
- TargetControlTypeAttribute.cs
- Msec.cs
- ControlCachePolicy.cs
- InkCanvasInnerCanvas.cs
- RecordsAffectedEventArgs.cs
- SafeTimerHandle.cs
- ClientWindowsAuthenticationMembershipProvider.cs
- AffineTransform3D.cs
- CompiledIdentityConstraint.cs