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
- AssemblyAssociatedContentFileAttribute.cs
- ListBoxItem.cs
- DoubleLink.cs
- EventWaitHandle.cs
- TerminatorSinks.cs
- WeakRefEnumerator.cs
- _ConnectOverlappedAsyncResult.cs
- TextSegment.cs
- FixedSOMLineCollection.cs
- DocumentGridPage.cs
- WebServiceResponseDesigner.cs
- StdValidatorsAndConverters.cs
- ControlTemplate.cs
- SuppressMergeCheckAttribute.cs
- ConstraintManager.cs
- odbcmetadatacolumnnames.cs
- AlternationConverter.cs
- TemplateXamlTreeBuilder.cs
- DocumentPageTextView.cs
- ProfilePropertySettings.cs
- IpcServerChannel.cs
- CoTaskMemHandle.cs
- WebReferenceCollection.cs
- PartitionerQueryOperator.cs
- DriveNotFoundException.cs
- GetKeyedHashRequest.cs
- GroupBoxAutomationPeer.cs
- CurrentTimeZone.cs
- SmtpFailedRecipientsException.cs
- _Win32.cs
- CodeMemberEvent.cs
- TextEmbeddedObject.cs
- HttpException.cs
- DataServices.cs
- ContextMenuService.cs
- DESCryptoServiceProvider.cs
- DataTablePropertyDescriptor.cs
- NativeMethods.cs
- DomNameTable.cs
- RegexCharClass.cs
- RawContentTypeMapper.cs
- BindingContext.cs
- WebBrowserSiteBase.cs
- EdmScalarPropertyAttribute.cs
- TemplateField.cs
- PolicyLevel.cs
- SettingsContext.cs
- GridViewItemAutomationPeer.cs
- RIPEMD160Managed.cs
- AppDomainUnloadedException.cs
- SelectionRange.cs
- HttpRequest.cs
- ErrorHandlerModule.cs
- ExceptionValidationRule.cs
- WpfPayload.cs
- RelatedView.cs
- DebugView.cs
- BoundConstants.cs
- RightsManagementLicense.cs
- KeyNotFoundException.cs
- MatrixAnimationBase.cs
- EdmComplexTypeAttribute.cs
- CodeFieldReferenceExpression.cs
- ServiceOperationListItemList.cs
- FlowDocumentFormatter.cs
- XmlILIndex.cs
- FacetEnabledSchemaElement.cs
- FixUpCollection.cs
- BidOverLoads.cs
- DtdParser.cs
- BufferModesCollection.cs
- Point3DCollection.cs
- ListSortDescriptionCollection.cs
- TypeExtensionConverter.cs
- TableLayout.cs
- GPRECT.cs
- QualifiedCellIdBoolean.cs
- PolicyConversionContext.cs
- StringStorage.cs
- FormViewInsertEventArgs.cs
- PersistenceMetadataNamespace.cs
- PermissionListSet.cs
- WebPartHelpVerb.cs
- ValueUtilsSmi.cs
- HtmlInputHidden.cs
- AttributeCollection.cs
- ToolStripSeparator.cs
- XPathMultyIterator.cs
- DbDataReader.cs
- TransactionScopeDesigner.cs
- ElasticEase.cs
- RuntimeConfigLKG.cs
- TokenizerHelper.cs
- RowParagraph.cs
- CodePageEncoding.cs
- ArrayExtension.cs
- VsPropertyGrid.cs
- DocobjHost.cs
- RootProfilePropertySettingsCollection.cs
- ReaderContextStackData.cs