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
- DocumentPageTextView.cs
- TypeInformation.cs
- Rule.cs
- Propagator.ExtentPlaceholderCreator.cs
- ProtectedProviderSettings.cs
- SplitterDesigner.cs
- TdsParameterSetter.cs
- StorageScalarPropertyMapping.cs
- updatecommandorderer.cs
- BrushValueSerializer.cs
- FileClassifier.cs
- TableLayoutStyleCollection.cs
- LocalValueEnumerator.cs
- EmptyQuery.cs
- Italic.cs
- ImmutablePropertyDescriptorGridEntry.cs
- ContentFilePart.cs
- MediaTimeline.cs
- ProfileParameter.cs
- WebBrowserHelper.cs
- DependencyPropertyValueSerializer.cs
- RestHandlerFactory.cs
- Screen.cs
- TextTreeTextBlock.cs
- DataGrid.cs
- Timeline.cs
- StylusCaptureWithinProperty.cs
- FastEncoderWindow.cs
- FormParameter.cs
- ClientBuildManagerTypeDescriptionProviderBridge.cs
- X509ChainElement.cs
- DataProtection.cs
- pingexception.cs
- ConstraintStruct.cs
- TemplateParser.cs
- XPathPatternBuilder.cs
- HtmlControlPersistable.cs
- ParameterElement.cs
- StyleSheet.cs
- Documentation.cs
- TextTreeRootNode.cs
- DataSourceHelper.cs
- SqlCachedBuffer.cs
- IFlowDocumentViewer.cs
- ParseNumbers.cs
- CodeDefaultValueExpression.cs
- StyleBamlTreeBuilder.cs
- StringConverter.cs
- SqlProvider.cs
- PromptEventArgs.cs
- BidOverLoads.cs
- TreeBuilderXamlTranslator.cs
- ColorConvertedBitmap.cs
- XmlSchemaValidator.cs
- PriorityBindingExpression.cs
- FileDetails.cs
- EmbeddedObject.cs
- ToolStripProgressBar.cs
- Globals.cs
- DataRelationCollection.cs
- QilReplaceVisitor.cs
- ByteViewer.cs
- TransactionsSectionGroup.cs
- Model3DGroup.cs
- AxisAngleRotation3D.cs
- ExpressionQuoter.cs
- Application.cs
- DataGridRowHeaderAutomationPeer.cs
- CollectionBuilder.cs
- RecipientInfo.cs
- MailDefinition.cs
- Select.cs
- PageTheme.cs
- AccessDataSourceView.cs
- ExcCanonicalXml.cs
- ElapsedEventArgs.cs
- IImplicitResourceProvider.cs
- SHA512Managed.cs
- ProviderCollection.cs
- _BaseOverlappedAsyncResult.cs
- LinearKeyFrames.cs
- MethodInfo.cs
- OuterGlowBitmapEffect.cs
- CodeDefaultValueExpression.cs
- Table.cs
- SafeFileHandle.cs
- RotateTransform.cs
- StyleSheet.cs
- SchemaImporter.cs
- SqlBulkCopy.cs
- HashAlgorithm.cs
- coordinator.cs
- RoutingExtension.cs
- ExpressionWriter.cs
- SqlClientWrapperSmiStreamChars.cs
- SelectQueryOperator.cs
- SimpleWebHandlerParser.cs
- ResourcePermissionBaseEntry.cs
- RequestUriProcessor.cs
- Bitmap.cs