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
- Button.cs
- TraceSection.cs
- AsyncCompletedEventArgs.cs
- XmlNodeList.cs
- PropertyChangeTracker.cs
- CodeDomSerializerBase.cs
- MapPathBasedVirtualPathProvider.cs
- RegistrySecurity.cs
- CreateUserErrorEventArgs.cs
- DPTypeDescriptorContext.cs
- RowsCopiedEventArgs.cs
- CultureInfoConverter.cs
- MSAAEventDispatcher.cs
- TypeRestriction.cs
- SqlDataSource.cs
- RoleManagerSection.cs
- ToolStripDropTargetManager.cs
- EnumerableValidator.cs
- PassportAuthentication.cs
- EpmCustomContentWriterNodeData.cs
- AttributeQuery.cs
- XmlDictionaryString.cs
- SoapAttributeOverrides.cs
- PathTooLongException.cs
- FormsAuthenticationUserCollection.cs
- SchemaConstraints.cs
- NavigationService.cs
- AnnotationResourceCollection.cs
- Timer.cs
- Socket.cs
- TypeRefElement.cs
- EnumDataContract.cs
- ObjectQueryExecutionPlan.cs
- UnsafePeerToPeerMethods.cs
- UrlAuthFailureHandler.cs
- DbProviderFactories.cs
- ListCollectionView.cs
- ListDictionaryInternal.cs
- SecurityPermission.cs
- OdbcConnectionStringbuilder.cs
- DetailsViewUpdatedEventArgs.cs
- AliasGenerator.cs
- BuilderElements.cs
- TextServicesManager.cs
- Brush.cs
- ValidationResult.cs
- SchemaTableColumn.cs
- EditCommandColumn.cs
- DataStreams.cs
- MarshalByValueComponent.cs
- CallbackDebugElement.cs
- SqlAliasesReferenced.cs
- SoapReflectionImporter.cs
- XsdDataContractExporter.cs
- SqlCommand.cs
- SetterBaseCollection.cs
- ControlTemplate.cs
- TcpChannelFactory.cs
- Compiler.cs
- StoreContentChangedEventArgs.cs
- SoapIgnoreAttribute.cs
- AddingNewEventArgs.cs
- TreeView.cs
- HierarchicalDataSourceControl.cs
- AtomContentProperty.cs
- EditingCoordinator.cs
- DependencyPropertyKind.cs
- Accessible.cs
- TypeUnloadedException.cs
- DependencyPropertyKey.cs
- XmlSchemaAll.cs
- ReflectTypeDescriptionProvider.cs
- DataConnectionHelper.cs
- OdbcDataReader.cs
- SkipQueryOptionExpression.cs
- QilFactory.cs
- RetrieveVirtualItemEventArgs.cs
- BrowserDefinition.cs
- SQLByteStorage.cs
- Timer.cs
- StateMachine.cs
- SafeRegistryHandle.cs
- DataGridViewCellPaintingEventArgs.cs
- HotSpot.cs
- SizeConverter.cs
- TargetControlTypeAttribute.cs
- WMIInterop.cs
- QueryStringParameter.cs
- _ConnectOverlappedAsyncResult.cs
- DataKeyArray.cs
- WebPartVerb.cs
- BitmapEffectState.cs
- XsltLibrary.cs
- Buffer.cs
- TimelineCollection.cs
- ConfigXmlWhitespace.cs
- NavigateEvent.cs
- OpenTypeLayoutCache.cs
- DataGridRelationshipRow.cs
- XmlNotation.cs