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
- odbcmetadatafactory.cs
- BamlRecordWriter.cs
- TaskForm.cs
- ReadOnlyDataSource.cs
- DependencyPropertyDescriptor.cs
- XmlComplianceUtil.cs
- GenericQueueSurrogate.cs
- LogLogRecord.cs
- VisualStyleTypesAndProperties.cs
- WriteFileContext.cs
- HtmlForm.cs
- Size.cs
- DataControlFieldHeaderCell.cs
- TreeNode.cs
- HtmlTextViewAdapter.cs
- EmptyEnumerator.cs
- NumberFormatter.cs
- StaticExtension.cs
- ListControlActionList.cs
- ZipIOExtraFieldZip64Element.cs
- AssertSection.cs
- WindowsStreamSecurityBindingElement.cs
- COM2TypeInfoProcessor.cs
- UnsafeNativeMethods.cs
- RowSpanVector.cs
- XsdValidatingReader.cs
- MenuEventArgs.cs
- ChtmlFormAdapter.cs
- EditorAttribute.cs
- XmlSchemaSimpleType.cs
- RowToFieldTransformer.cs
- WithParamAction.cs
- DefaultTraceListener.cs
- PageBreakRecord.cs
- odbcmetadatacolumnnames.cs
- LogicalExpr.cs
- FragmentQueryKB.cs
- DataTableMapping.cs
- StateMachine.cs
- ToolStripScrollButton.cs
- MetadataPropertyvalue.cs
- AppDomainManager.cs
- ListViewContainer.cs
- TreeSet.cs
- ItemCollection.cs
- SqlBooleanizer.cs
- ThreadPoolTaskScheduler.cs
- backend.cs
- XmlSerializationGeneratedCode.cs
- MyContact.cs
- SqlBuilder.cs
- MenuStrip.cs
- ImmComposition.cs
- SynchronizationContext.cs
- CaseCqlBlock.cs
- InternalsVisibleToAttribute.cs
- ToolStrip.cs
- SeverityFilter.cs
- MonthChangedEventArgs.cs
- UrlRoutingModule.cs
- ResourceDescriptionAttribute.cs
- PermissionRequestEvidence.cs
- ResourceWriter.cs
- SiteMapPath.cs
- TreeViewDesigner.cs
- XmlCodeExporter.cs
- SupportsEventValidationAttribute.cs
- RefType.cs
- EllipticalNodeOperations.cs
- Matrix3DStack.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- COM2PictureConverter.cs
- Normalization.cs
- ChtmlLinkAdapter.cs
- SafeBitVector32.cs
- ResourceManager.cs
- DisplayInformation.cs
- CallbackHandler.cs
- DataException.cs
- SecurityHelper.cs
- MaterializeFromAtom.cs
- ComponentSerializationService.cs
- TileModeValidation.cs
- OpacityConverter.cs
- AccessedThroughPropertyAttribute.cs
- PathFigure.cs
- PointValueSerializer.cs
- SystemInfo.cs
- SaveFileDialog.cs
- EditorPartChrome.cs
- XhtmlTextWriter.cs
- PropertyGrid.cs
- ExceptionValidationRule.cs
- Metadata.cs
- MsmqIntegrationMessagePool.cs
- PageAdapter.cs
- SrgsRuleRef.cs
- ComponentDispatcherThread.cs
- UnsafeNativeMethodsPenimc.cs
- SignedXml.cs