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
- BitmapFrameDecode.cs
- CodeAttributeDeclarationCollection.cs
- WebAdminConfigurationHelper.cs
- InlineUIContainer.cs
- Scripts.cs
- IListConverters.cs
- SafeFindHandle.cs
- AutomationPatternInfo.cs
- DateTimeFormatInfo.cs
- TemplateBindingExpression.cs
- DNS.cs
- CorrelationService.cs
- TypedDataSourceCodeGenerator.cs
- ContainerParagraph.cs
- HttpStreamXmlDictionaryWriter.cs
- GridViewSelectEventArgs.cs
- GraphicsPathIterator.cs
- ResetableIterator.cs
- mda.cs
- ForceCopyBuildProvider.cs
- DataGridViewCellStyle.cs
- GroupBoxRenderer.cs
- XDeferredAxisSource.cs
- DataListCommandEventArgs.cs
- XsltArgumentList.cs
- LoadWorkflowByKeyAsyncResult.cs
- SafePEFileHandle.cs
- ClientFormsIdentity.cs
- SplitterEvent.cs
- InvalidateEvent.cs
- TypeReference.cs
- XmlSchemaSimpleContentExtension.cs
- InvokePattern.cs
- EventWaitHandle.cs
- WizardPanelChangingEventArgs.cs
- Clipboard.cs
- BrushValueSerializer.cs
- PathSegmentCollection.cs
- GenerateScriptTypeAttribute.cs
- TagPrefixCollection.cs
- ExternalCalls.cs
- Hashtable.cs
- PointConverter.cs
- ConfigurationStrings.cs
- Buffer.cs
- PropertyCondition.cs
- XhtmlBasicPanelAdapter.cs
- ResourceCategoryAttribute.cs
- FontEmbeddingManager.cs
- sqlstateclientmanager.cs
- sqlpipe.cs
- ImageField.cs
- SystemInfo.cs
- Pen.cs
- Win32NamedPipes.cs
- DefaultCommandConverter.cs
- SqlExpander.cs
- WmlPhoneCallAdapter.cs
- SqlServer2KCompatibilityAnnotation.cs
- DefaultTraceListener.cs
- StateMachine.cs
- MissingMethodException.cs
- PenThread.cs
- WinEventWrap.cs
- SafeRightsManagementHandle.cs
- TheQuery.cs
- SettingsSection.cs
- ButtonChrome.cs
- DoubleMinMaxAggregationOperator.cs
- ObservableDictionary.cs
- DataGridView.cs
- SQLDateTime.cs
- HttpListenerContext.cs
- NativeMethods.cs
- PropertySegmentSerializer.cs
- AmbientLight.cs
- XmlWhitespace.cs
- FontStretchConverter.cs
- IncrementalCompileAnalyzer.cs
- LineGeometry.cs
- EntityDataSourceStatementEditor.cs
- NullNotAllowedCollection.cs
- RegexTree.cs
- DomainUpDown.cs
- SpecialFolderEnumConverter.cs
- ScrollItemPatternIdentifiers.cs
- PropertyMapper.cs
- ExecutionPropertyManager.cs
- XmlDataFileEditor.cs
- RepeaterItemCollection.cs
- TextBoxAutoCompleteSourceConverter.cs
- _UriSyntax.cs
- Environment.cs
- UrlPropertyAttribute.cs
- Privilege.cs
- validationstate.cs
- ValidatorUtils.cs
- TransmissionStrategy.cs
- DocumentsTrace.cs
- ConfigXmlSignificantWhitespace.cs