Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BorderGapMaskConverter.cs
- MergeExecutor.cs
- PackageRelationshipCollection.cs
- ForeignConstraint.cs
- CmsUtils.cs
- RowTypePropertyElement.cs
- TypeBrowser.xaml.cs
- EllipseGeometry.cs
- XmlSchemaChoice.cs
- DataTableCollection.cs
- ModelServiceImpl.cs
- LineGeometry.cs
- EditorOptionAttribute.cs
- ProtocolsConfiguration.cs
- DataGridViewBand.cs
- IPipelineRuntime.cs
- WebEventTraceProvider.cs
- Timer.cs
- SQLInt64Storage.cs
- WhitespaceSignificantCollectionAttribute.cs
- PartBasedPackageProperties.cs
- ToolStripItemRenderEventArgs.cs
- PriorityBindingExpression.cs
- QueueProcessor.cs
- EventLog.cs
- CultureSpecificCharacterBufferRange.cs
- UserNameSecurityTokenProvider.cs
- UnorderedHashRepartitionStream.cs
- QueryExpr.cs
- GiveFeedbackEventArgs.cs
- MatrixAnimationUsingPath.cs
- ISCIIEncoding.cs
- SecurityException.cs
- RemotingServices.cs
- SettingsContext.cs
- RepeaterItemEventArgs.cs
- LocationUpdates.cs
- InvalidWMPVersionException.cs
- LogAppendAsyncResult.cs
- EntityDataSourceWizardForm.cs
- DefaultShape.cs
- CollectionView.cs
- ByteAnimation.cs
- JavaScriptString.cs
- PointCollectionConverter.cs
- SingleResultAttribute.cs
- MD5CryptoServiceProvider.cs
- WebCategoryAttribute.cs
- StateDesigner.Helpers.cs
- ObjectDataSourceMethodEventArgs.cs
- WebPartChrome.cs
- SafeFreeMibTable.cs
- XmlNavigatorFilter.cs
- StaticExtension.cs
- Int32Collection.cs
- TemplateBuilder.cs
- OracleInfoMessageEventArgs.cs
- CalendarDayButton.cs
- DataGridSortCommandEventArgs.cs
- ExpandableObjectConverter.cs
- RepeaterCommandEventArgs.cs
- UnaryNode.cs
- COAUTHIDENTITY.cs
- CompareInfo.cs
- DateTime.cs
- DataRecordInfo.cs
- ConnectionStringsExpressionBuilder.cs
- TextElementAutomationPeer.cs
- AddressHeaderCollectionElement.cs
- ChangeConflicts.cs
- InvalidCommandTreeException.cs
- VectorAnimation.cs
- DataPagerField.cs
- PriorityQueue.cs
- ButtonBase.cs
- LicFileLicenseProvider.cs
- RemoveStoryboard.cs
- ServiceMemoryGates.cs
- XNodeSchemaApplier.cs
- LinqDataSourceStatusEventArgs.cs
- QuaternionValueSerializer.cs
- ReflectionPermission.cs
- LogEntryHeaderSerializer.cs
- StorageAssociationSetMapping.cs
- SQLByte.cs
- DiffuseMaterial.cs
- ExpressionsCollectionEditor.cs
- DataRecordInfo.cs
- XmlSchemaFacet.cs
- XsltInput.cs
- TextRenderer.cs
- StrongNameIdentityPermission.cs
- GeneralTransform.cs
- EventPropertyMap.cs
- DebugController.cs
- CodeGen.cs
- QfeChecker.cs
- Decimal.cs
- OLEDB_Util.cs
- Color.cs