Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / 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; } } }
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ObjectView.cs
- XmlSerializer.cs
- HealthMonitoringSectionHelper.cs
- SByteConverter.cs
- AllMembershipCondition.cs
- BitmapEffectInputConnector.cs
- ClientTargetCollection.cs
- ObjectItemCachedAssemblyLoader.cs
- Subtree.cs
- PolyBezierSegment.cs
- XmlSchemaSimpleTypeRestriction.cs
- prompt.cs
- FeatureAttribute.cs
- XPathPatternParser.cs
- SoapParser.cs
- ProcessModuleCollection.cs
- TemplateBindingExpressionConverter.cs
- XmlILModule.cs
- RuleSettings.cs
- EncoderExceptionFallback.cs
- XmlDocumentSerializer.cs
- DataGridToolTip.cs
- FramingChannels.cs
- ContentElementAutomationPeer.cs
- HttpCookieCollection.cs
- DecoderFallback.cs
- GenericIdentity.cs
- SqlAliasesReferenced.cs
- VisualBrush.cs
- HttpCachePolicy.cs
- PointCollectionConverter.cs
- ChangeProcessor.cs
- MobileControlDesigner.cs
- AstTree.cs
- CriticalHandle.cs
- WindowsImpersonationContext.cs
- MouseGesture.cs
- InfoCardClaim.cs
- CachedBitmap.cs
- configsystem.cs
- ListSortDescriptionCollection.cs
- DBSchemaRow.cs
- KeyPressEvent.cs
- SafeNativeMethods.cs
- BufferModesCollection.cs
- UnknownWrapper.cs
- SafeCryptoHandles.cs
- DataGridParentRows.cs
- ListBindingConverter.cs
- RtfToken.cs
- CompilerLocalReference.cs
- FlowDocumentScrollViewer.cs
- DSASignatureFormatter.cs
- RevocationPoint.cs
- CategoryNameCollection.cs
- XmlBindingWorker.cs
- DecodeHelper.cs
- SqlFunctionAttribute.cs
- SqlDependency.cs
- TextServicesDisplayAttribute.cs
- SendMailErrorEventArgs.cs
- Solver.cs
- ApplyTemplatesAction.cs
- FloaterParagraph.cs
- ThreadStartException.cs
- DataGridLinkButton.cs
- XmlByteStreamReader.cs
- SQLInt64.cs
- SpeakCompletedEventArgs.cs
- TextTreeObjectNode.cs
- SortDescriptionCollection.cs
- DataTrigger.cs
- AncestorChangedEventArgs.cs
- ListDesigner.cs
- AutoGeneratedField.cs
- TrackPointCollection.cs
- ValidationSummary.cs
- DesignConnection.cs
- SqlDependencyListener.cs
- SupportedAddressingMode.cs
- DrawingCollection.cs
- GraphicsState.cs
- PropertyEntry.cs
- TextPenaltyModule.cs
- ResourcesGenerator.cs
- MaterialCollection.cs
- SafeMarshalContext.cs
- SafeEventLogReadHandle.cs
- ResXBuildProvider.cs
- OleDbException.cs
- AjaxFrameworkAssemblyAttribute.cs
- OrCondition.cs
- TextBlockAutomationPeer.cs
- GenericTextProperties.cs
- HideDisabledControlAdapter.cs
- TextShapeableCharacters.cs
- AnnotationAuthorChangedEventArgs.cs
- QueryContinueDragEventArgs.cs
- X509CertificateInitiatorClientCredential.cs
- IndependentAnimationStorage.cs