Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- GPPOINTF.cs
- SqlRemoveConstantOrderBy.cs
- ApplicationDirectoryMembershipCondition.cs
- XmlExceptionHelper.cs
- OracleString.cs
- TableCellCollection.cs
- Model3DGroup.cs
- DbConnectionHelper.cs
- EpmContentDeSerializerBase.cs
- VerificationException.cs
- SymbolEqualComparer.cs
- WebPartMenuStyle.cs
- SecurityManager.cs
- NamedObjectList.cs
- Delay.cs
- XmlAutoDetectWriter.cs
- ConfigXmlText.cs
- RemoteX509Token.cs
- MinimizableAttributeTypeConverter.cs
- Util.cs
- PKCS1MaskGenerationMethod.cs
- Trace.cs
- IncrementalCompileAnalyzer.cs
- TraceHwndHost.cs
- VersionedStream.cs
- TrackBarRenderer.cs
- Point.cs
- SecurityManager.cs
- ObjectStorage.cs
- ListSourceHelper.cs
- XmlStreamStore.cs
- RequestDescription.cs
- TextServicesContext.cs
- ConfigXmlElement.cs
- HierarchicalDataSourceConverter.cs
- WebServiceMethodData.cs
- SoapFault.cs
- FullTextLine.cs
- LoginName.cs
- HtmlInputSubmit.cs
- FastPropertyAccessor.cs
- ArgumentValue.cs
- ResourcePermissionBaseEntry.cs
- Switch.cs
- TypeConverterAttribute.cs
- QueryAsyncResult.cs
- ListViewGroupConverter.cs
- ByteConverter.cs
- NeutralResourcesLanguageAttribute.cs
- SmiEventStream.cs
- CursorConverter.cs
- ExtensionCollection.cs
- DataContract.cs
- GradientPanel.cs
- WebPartEditorApplyVerb.cs
- RenderingBiasValidation.cs
- ViewManager.cs
- MappingMetadataHelper.cs
- SoapTransportImporter.cs
- templategroup.cs
- Error.cs
- TraceHwndHost.cs
- ImmutableCollection.cs
- RayHitTestParameters.cs
- WSSecurityOneDotZeroReceiveSecurityHeader.cs
- CryptoConfig.cs
- ManipulationDeltaEventArgs.cs
- GregorianCalendarHelper.cs
- PrivilegedConfigurationManager.cs
- MenuRenderer.cs
- InputBuffer.cs
- TransformedBitmap.cs
- SetIndexBinder.cs
- ExpressionNormalizer.cs
- BamlMapTable.cs
- PrimarySelectionAdorner.cs
- AsnEncodedData.cs
- PrintController.cs
- Base64WriteStateInfo.cs
- MenuCommand.cs
- LocalsItemDescription.cs
- HMACSHA384.cs
- SqlWriter.cs
- DetailsViewModeEventArgs.cs
- GetWinFXPath.cs
- SparseMemoryStream.cs
- Assert.cs
- BulletedList.cs
- EntityDesignerUtils.cs
- DynamicArgumentDesigner.xaml.cs
- mongolianshape.cs
- CodeValidator.cs
- Source.cs
- uribuilder.cs
- ReflectionHelper.cs
- GeneralTransformGroup.cs
- ServiceDurableInstance.cs
- RuntimeConfigLKG.cs
- BlockCollection.cs
- XmlTextAttribute.cs