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
- SHA1.cs
- XmlParserContext.cs
- AssemblyCollection.cs
- LocatorPartList.cs
- Comparer.cs
- SystemIPInterfaceStatistics.cs
- XPathNodeHelper.cs
- MappingModelBuildProvider.cs
- SafeFreeMibTable.cs
- ColorConvertedBitmap.cs
- JsonStringDataContract.cs
- RequestQueue.cs
- LineBreakRecord.cs
- ParameterReplacerVisitor.cs
- AuthenticationManager.cs
- TTSEvent.cs
- InstancePersistenceCommandException.cs
- SymbolEqualComparer.cs
- XmlReaderDelegator.cs
- SiteMapSection.cs
- ToolStripPanelRenderEventArgs.cs
- HelloOperationCD1AsyncResult.cs
- MutexSecurity.cs
- HyperLinkDesigner.cs
- PageContentAsyncResult.cs
- RectangleGeometry.cs
- ImageSource.cs
- ValidationPropertyAttribute.cs
- CodeMemberEvent.cs
- MessagePropertyFilter.cs
- HistoryEventArgs.cs
- FormatConvertedBitmap.cs
- SmiContext.cs
- DataGridColumnFloatingHeader.cs
- ListViewInsertedEventArgs.cs
- PackagingUtilities.cs
- _DigestClient.cs
- ResourcesChangeInfo.cs
- XMLDiffLoader.cs
- DocumentXPathNavigator.cs
- LongValidator.cs
- ClientSettings.cs
- TableItemPattern.cs
- MethodImplAttribute.cs
- CryptoKeySecurity.cs
- WinEventWrap.cs
- FileFormatException.cs
- FlowLayoutPanel.cs
- EventProviderWriter.cs
- ScriptRegistrationManager.cs
- Thread.cs
- SystemSounds.cs
- DataGridViewUtilities.cs
- ColorIndependentAnimationStorage.cs
- __Filters.cs
- WSSecurityPolicy.cs
- XmlDataContract.cs
- SctClaimSerializer.cs
- BaseParagraph.cs
- Main.cs
- AddIn.cs
- MULTI_QI.cs
- StorageAssociationSetMapping.cs
- TableRowCollection.cs
- ListViewContainer.cs
- FilterQuery.cs
- RelationshipConverter.cs
- Style.cs
- CopyOfAction.cs
- Speller.cs
- EntityDataSourceWrapper.cs
- DoubleLinkListEnumerator.cs
- StructureChangedEventArgs.cs
- DataTable.cs
- AlternationConverter.cs
- OrderByExpression.cs
- Int32KeyFrameCollection.cs
- BamlTreeMap.cs
- FileInfo.cs
- VariantWrapper.cs
- PageAsyncTask.cs
- TextRangeEditLists.cs
- StandardBindingElementCollection.cs
- SharedHttpsTransportManager.cs
- SequentialWorkflowHeaderFooter.cs
- Speller.cs
- XNodeNavigator.cs
- SqlUserDefinedTypeAttribute.cs
- XmlnsDictionary.cs
- _NativeSSPI.cs
- XmlHierarchicalDataSourceView.cs
- OleDbPermission.cs
- RoutedUICommand.cs
- SignatureTargetIdManager.cs
- StringAnimationBase.cs
- DecoderReplacementFallback.cs
- ConnectionStringsSection.cs
- DateTimeOffset.cs
- WindowsTab.cs
- EditorPartChrome.cs