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
- XmlILIndex.cs
- MachineKeyConverter.cs
- FieldBuilder.cs
- ProxyWebPartManager.cs
- ping.cs
- AnimationException.cs
- XmlAnyElementAttributes.cs
- relpropertyhelper.cs
- EdmSchemaError.cs
- RecordManager.cs
- UpDownEvent.cs
- TrackingServices.cs
- SafeFileMappingHandle.cs
- StrokeCollectionConverter.cs
- SspiNegotiationTokenAuthenticator.cs
- CodeTypeDeclarationCollection.cs
- AggregateNode.cs
- DependencyPropertyChangedEventArgs.cs
- Table.cs
- LocalizationParserHooks.cs
- HyperLinkStyle.cs
- MatrixCamera.cs
- AuthStoreRoleProvider.cs
- MethodRental.cs
- ProcessInfo.cs
- DataControlPagerLinkButton.cs
- TextEncodedRawTextWriter.cs
- AttributeEmitter.cs
- RequestTimeoutManager.cs
- HorizontalAlignConverter.cs
- Terminate.cs
- OpenTypeLayoutCache.cs
- DesignerActionService.cs
- OdbcCommandBuilder.cs
- FileController.cs
- ElementFactory.cs
- ConfigurationStrings.cs
- DetailsViewDeletedEventArgs.cs
- Item.cs
- DataBoundControlHelper.cs
- TextSearch.cs
- UnsafeNativeMethods.cs
- SqlNotificationRequest.cs
- ViewStateException.cs
- PrintingPermission.cs
- DeviceContext.cs
- VariableQuery.cs
- Type.cs
- DeleteIndexBinder.cs
- MenuItem.cs
- ConditionCollection.cs
- DataTemplate.cs
- AdapterDictionary.cs
- Menu.cs
- QueryStringHandler.cs
- BinHexEncoding.cs
- ScrollBar.cs
- Pens.cs
- SpecialNameAttribute.cs
- WebPageTraceListener.cs
- WebPartDisplayModeEventArgs.cs
- EditorPartChrome.cs
- VersionedStream.cs
- ConfigurationStrings.cs
- HitTestResult.cs
- FormatException.cs
- FontUnit.cs
- GuidTagList.cs
- HtmlInputCheckBox.cs
- XamlTemplateSerializer.cs
- PerformanceCounterNameAttribute.cs
- WebPartConnectionsConnectVerb.cs
- _IPv4Address.cs
- RadioButtonRenderer.cs
- CriticalExceptions.cs
- SqlInternalConnectionSmi.cs
- PropertyCondition.cs
- PropertyChangedEventManager.cs
- IndividualDeviceConfig.cs
- WindowsTokenRoleProvider.cs
- BaseProcessor.cs
- EntitySqlQueryBuilder.cs
- PerSessionInstanceContextProvider.cs
- PerfService.cs
- FtpRequestCacheValidator.cs
- BamlReader.cs
- ButtonPopupAdapter.cs
- DeploymentSection.cs
- TokenBasedSet.cs
- ModelPerspective.cs
- PreProcessor.cs
- MediaContext.cs
- WebConfigManager.cs
- InputLanguageEventArgs.cs
- Vector3DCollection.cs
- HttpMethodConstraint.cs
- ClientRoleProvider.cs
- SemanticAnalyzer.cs
- processwaithandle.cs
- RepeaterItemEventArgs.cs