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
- MarkerProperties.cs
- XmlComplianceUtil.cs
- Context.cs
- DbProviderFactories.cs
- Convert.cs
- Filter.cs
- DataGridViewControlCollection.cs
- X509InitiatorCertificateServiceElement.cs
- ConvertEvent.cs
- ObservableCollection.cs
- DropShadowBitmapEffect.cs
- FileSecurity.cs
- TextProperties.cs
- SHA256Managed.cs
- DataGridViewRowsAddedEventArgs.cs
- XmlResolver.cs
- DesignTimeVisibleAttribute.cs
- FontCollection.cs
- BasicExpressionVisitor.cs
- VarRefManager.cs
- MenuItemStyle.cs
- HtmlShim.cs
- GridViewItemAutomationPeer.cs
- KnownTypesHelper.cs
- ForeignConstraint.cs
- InfoCardBaseException.cs
- TableParagraph.cs
- CodeDOMUtility.cs
- CultureMapper.cs
- MetadataArtifactLoader.cs
- WebSysDescriptionAttribute.cs
- EndpointIdentityConverter.cs
- ProfileParameter.cs
- ChildrenQuery.cs
- CancelEventArgs.cs
- ConfigurationManagerHelperFactory.cs
- CharKeyFrameCollection.cs
- PointLight.cs
- ProxyWebPartManager.cs
- Schema.cs
- ForeignKeyFactory.cs
- CacheDependency.cs
- QilNode.cs
- SoapSchemaExporter.cs
- storepermission.cs
- EnumMemberAttribute.cs
- SqlRowUpdatedEvent.cs
- PresentationTraceSources.cs
- x509store.cs
- DoubleAnimationUsingPath.cs
- _LazyAsyncResult.cs
- SizeConverter.cs
- xsdvalidator.cs
- AssemblyBuilder.cs
- ImpersonationContext.cs
- smtppermission.cs
- ComponentChangingEvent.cs
- Thickness.cs
- WpfWebRequestHelper.cs
- MsmqChannelFactoryBase.cs
- TemplateNameScope.cs
- SqlConnectionHelper.cs
- GroupItem.cs
- SctClaimDictionary.cs
- JumpList.cs
- IntAverageAggregationOperator.cs
- MediaPlayer.cs
- Wow64ConfigurationLoader.cs
- SqlDataAdapter.cs
- DictionaryManager.cs
- SystemIcmpV6Statistics.cs
- HandlerMappingMemo.cs
- Config.cs
- WebPartEditVerb.cs
- RouteItem.cs
- DelegateSerializationHolder.cs
- ExtendedProtectionPolicyElement.cs
- TransactionScopeDesigner.cs
- ImageConverter.cs
- DetailsViewInsertedEventArgs.cs
- WhereQueryOperator.cs
- JavaScriptSerializer.cs
- AttributeXamlType.cs
- HtmlInputHidden.cs
- WindowsFormsHostPropertyMap.cs
- TimeSpanConverter.cs
- assertwrapper.cs
- ShaperBuffers.cs
- NavigatorOutput.cs
- OracleRowUpdatingEventArgs.cs
- IndentedWriter.cs
- PropertyValueChangedEvent.cs
- Compiler.cs
- BaseTemplateBuildProvider.cs
- PropertyGridView.cs
- UnsettableComboBox.cs
- ExtensibleClassFactory.cs
- LiteralTextParser.cs
- WebReferenceOptions.cs
- DrawingDrawingContext.cs