Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / infocard / Client / System / IdentityModel / Selectors / SafeLibraryHandle.cs / 1305376 / SafeLibraryHandle.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.IdentityModel.Selectors { using System; using System.IO; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.InteropServices; using System.Runtime.ConstrainedExecution; using System.Runtime.CompilerServices; using Microsoft.InfoCards.Diagnostics; using Microsoft.Win32; using System.Security.Permissions; using Microsoft.Win32.SafeHandles; // // Summary: // A class to wrap a library handle for reliability. // When LoadLibrary returns, the runtime stores the resulting IntPtr // into the already created SafeLibraryHandle. The runtime guarantees that // this operation is atomic, meaning that if the P/Invoke method successfully returns, // the IntPtr will be stored safely inside the SafeHandle. Once inside the SafeHandle, // even if an asynchronous exception occurs and prevents LoadLibrary's SafeLibraryHandle return // value from being stored, the relevant IntPtr is already stored within a managed object // whose critical finalizer will ensure its proper release. // [ SecurityPermission( SecurityAction.LinkDemand, UnmanagedCode=true ) ] class SafeLibraryHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeLibraryHandle() : base( true ) { } protected override bool ReleaseHandle() { #pragma warning suppress 56523 return FreeLibrary( handle ); } [DllImport( "kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true, CallingConvention = CallingConvention.StdCall )] internal static extern SafeLibraryHandle LoadLibraryW( [MarshalAs( UnmanagedType.LPWStr )] string dllname ); [DllImport( "kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true, CallingConvention = CallingConvention.StdCall )] internal static extern bool FreeLibrary( IntPtr hModule ); } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.IdentityModel.Selectors { using System; using System.IO; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.InteropServices; using System.Runtime.ConstrainedExecution; using System.Runtime.CompilerServices; using Microsoft.InfoCards.Diagnostics; using Microsoft.Win32; using System.Security.Permissions; using Microsoft.Win32.SafeHandles; // // Summary: // A class to wrap a library handle for reliability. // When LoadLibrary returns, the runtime stores the resulting IntPtr // into the already created SafeLibraryHandle. The runtime guarantees that // this operation is atomic, meaning that if the P/Invoke method successfully returns, // the IntPtr will be stored safely inside the SafeHandle. Once inside the SafeHandle, // even if an asynchronous exception occurs and prevents LoadLibrary's SafeLibraryHandle return // value from being stored, the relevant IntPtr is already stored within a managed object // whose critical finalizer will ensure its proper release. // [ SecurityPermission( SecurityAction.LinkDemand, UnmanagedCode=true ) ] class SafeLibraryHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeLibraryHandle() : base( true ) { } protected override bool ReleaseHandle() { #pragma warning suppress 56523 return FreeLibrary( handle ); } [DllImport( "kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true, CallingConvention = CallingConvention.StdCall )] internal static extern SafeLibraryHandle LoadLibraryW( [MarshalAs( UnmanagedType.LPWStr )] string dllname ); [DllImport( "kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true, CallingConvention = CallingConvention.StdCall )] internal static extern bool FreeLibrary( IntPtr hModule ); } } // 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
- SQLInt64Storage.cs
- DisableDpiAwarenessAttribute.cs
- OrderByBuilder.cs
- CodeExpressionStatement.cs
- SoapMessage.cs
- VirtualDirectoryMapping.cs
- User.cs
- IConvertible.cs
- GridPattern.cs
- DataGridGeneralPage.cs
- ManagementEventWatcher.cs
- FixedPageProcessor.cs
- MimeXmlImporter.cs
- FlowDocumentScrollViewer.cs
- XsdBuildProvider.cs
- HttpHandlerActionCollection.cs
- GeneralTransform3DGroup.cs
- SqlTransaction.cs
- ConnectionPoint.cs
- MatrixConverter.cs
- SliderAutomationPeer.cs
- DeclarativeCatalogPartDesigner.cs
- SqlUnionizer.cs
- diagnosticsswitches.cs
- WindowsTab.cs
- FloaterBaseParaClient.cs
- ExceptionValidationRule.cs
- TimeSpan.cs
- EntityRecordInfo.cs
- VectorConverter.cs
- DataBindEngine.cs
- SpnegoTokenProvider.cs
- DocumentGridContextMenu.cs
- MethodBody.cs
- OrderedDictionary.cs
- ToolStripStatusLabel.cs
- _NestedMultipleAsyncResult.cs
- RightNameExpirationInfoPair.cs
- CodeAccessSecurityEngine.cs
- CompilationPass2Task.cs
- CancellationHandlerDesigner.cs
- BitmapMetadata.cs
- PropertyChangingEventArgs.cs
- UxThemeWrapper.cs
- RequestCachePolicy.cs
- DBConcurrencyException.cs
- InheritanceContextChangedEventManager.cs
- GroupStyle.cs
- Model3D.cs
- PropertyExpression.cs
- ConfigurationValue.cs
- safelinkcollection.cs
- Paragraph.cs
- CommandField.cs
- RequestUriProcessor.cs
- ObjectListField.cs
- SingleConverter.cs
- Point3D.cs
- ManifestResourceInfo.cs
- XmlDataSource.cs
- FullTextBreakpoint.cs
- newitemfactory.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- XPathNavigatorKeyComparer.cs
- ServiceDescriptions.cs
- HttpContextServiceHost.cs
- DataGridViewRowHeaderCell.cs
- Point3D.cs
- x509utils.cs
- Setter.cs
- JournalNavigationScope.cs
- BezierSegment.cs
- TraceHandlerErrorFormatter.cs
- TdsEnums.cs
- GcHandle.cs
- NamedPermissionSet.cs
- Ipv6Element.cs
- HtmlHistory.cs
- FormsAuthenticationConfiguration.cs
- HttpPostProtocolImporter.cs
- _BufferOffsetSize.cs
- SchemaInfo.cs
- TextureBrush.cs
- MatrixCamera.cs
- PaperSource.cs
- MiniLockedBorderGlyph.cs
- CharacterBufferReference.cs
- CornerRadiusConverter.cs
- WebPartUtil.cs
- RuleAttributes.cs
- _NestedMultipleAsyncResult.cs
- TrackingProfileCache.cs
- sqlcontext.cs
- TextParaClient.cs
- BitVec.cs
- StateRuntime.cs
- DropShadowBitmapEffect.cs
- DataGridViewCheckBoxColumn.cs
- StyleModeStack.cs
- SchemaConstraints.cs