Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / Media / SafeReversePInvokeHandle.cs / 1305600 / SafeReversePInvokeHandle.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: // A safe way to deal with unmanaged MIL interface pointers. //--------------------------------------------------------------------------- using System; using System.IO; using System.Security; using System.Security.Permissions; using System.Collections; using System.Reflection; using MS.Internal; using MS.Win32; using System.Diagnostics; using System.Windows.Media; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; using Microsoft.Internal; using UnsafeNativeMethods=MS.Win32.PresentationCore.UnsafeNativeMethods; namespace System.Windows.Media { internal class SafeReversePInvokeWrapper : SafeHandleZeroOrMinusOneIsInvalid { ////// Use this constructor if the handle isn't ready yet and later /// set the handle with SetHandle. SafeMILHandle owns the release /// of the handle. /// ////// Critical: This derives from a class that has a link demand and inheritance demand /// TreatAsSafe: Ok to call constructor /// [SecurityCritical] internal SafeReversePInvokeWrapper() : base(true) { } ////// Use this constructor if the handle exists at construction time. /// SafeMILHandle owns the release of the parameter. /// ////// Calls into native code to wrap a reverse p-invoke delegate into a CReversePInvokeDelegateWrapper. /// [SecurityCritical] internal SafeReversePInvokeWrapper(IntPtr delegatePtr) : base(true) { // Wrap the reverse p-invoke into a reversePInvokeWrapper. IntPtr reversePInvokeWrapper; HRESULT.Check(UnsafeNativeMethods.MilCoreApi.MilCreateReversePInvokeWrapper(delegatePtr, out reversePInvokeWrapper)); SetHandle(reversePInvokeWrapper); } ////// Critical - calls unmanaged code, not treat as safe because you must /// validate that handle is a valid COM object. /// [SecurityCritical] protected override bool ReleaseHandle() { if (handle != IntPtr.Zero) { UnsafeNativeMethods.MilCoreApi.MilReleasePInvokePtrBlocking(handle); } UnsafeNativeMethods.MILUnknown.ReleaseInterface(ref handle); return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: // A safe way to deal with unmanaged MIL interface pointers. //--------------------------------------------------------------------------- using System; using System.IO; using System.Security; using System.Security.Permissions; using System.Collections; using System.Reflection; using MS.Internal; using MS.Win32; using System.Diagnostics; using System.Windows.Media; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; using Microsoft.Internal; using UnsafeNativeMethods=MS.Win32.PresentationCore.UnsafeNativeMethods; namespace System.Windows.Media { internal class SafeReversePInvokeWrapper : SafeHandleZeroOrMinusOneIsInvalid { ////// Use this constructor if the handle isn't ready yet and later /// set the handle with SetHandle. SafeMILHandle owns the release /// of the handle. /// ////// Critical: This derives from a class that has a link demand and inheritance demand /// TreatAsSafe: Ok to call constructor /// [SecurityCritical] internal SafeReversePInvokeWrapper() : base(true) { } ////// Use this constructor if the handle exists at construction time. /// SafeMILHandle owns the release of the parameter. /// ////// Calls into native code to wrap a reverse p-invoke delegate into a CReversePInvokeDelegateWrapper. /// [SecurityCritical] internal SafeReversePInvokeWrapper(IntPtr delegatePtr) : base(true) { // Wrap the reverse p-invoke into a reversePInvokeWrapper. IntPtr reversePInvokeWrapper; HRESULT.Check(UnsafeNativeMethods.MilCoreApi.MilCreateReversePInvokeWrapper(delegatePtr, out reversePInvokeWrapper)); SetHandle(reversePInvokeWrapper); } ////// Critical - calls unmanaged code, not treat as safe because you must /// validate that handle is a valid COM object. /// [SecurityCritical] protected override bool ReleaseHandle() { if (handle != IntPtr.Zero) { UnsafeNativeMethods.MilCoreApi.MilReleasePInvokePtrBlocking(handle); } UnsafeNativeMethods.MILUnknown.ReleaseInterface(ref handle); return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BaseTemplateParser.cs
- SoapEnumAttribute.cs
- EncryptedXml.cs
- HiddenFieldPageStatePersister.cs
- ViewEvent.cs
- RbTree.cs
- TextEndOfLine.cs
- WhitespaceSignificantCollectionAttribute.cs
- DSASignatureDeformatter.cs
- EntityDataSourceMemberPath.cs
- OrderedEnumerableRowCollection.cs
- VirtualPathProvider.cs
- WebPartConnectionsEventArgs.cs
- InternalConfigSettingsFactory.cs
- MultiPropertyDescriptorGridEntry.cs
- RootCodeDomSerializer.cs
- wmiutil.cs
- RoleManagerModule.cs
- UriParserTemplates.cs
- BaseCodeDomTreeGenerator.cs
- COAUTHIDENTITY.cs
- Focus.cs
- CreateUserWizardAutoFormat.cs
- MobileTextWriter.cs
- WebPartsSection.cs
- SignatureResourceHelper.cs
- BinaryMessageFormatter.cs
- StringConcat.cs
- PrinterResolution.cs
- PreservationFileWriter.cs
- VisualStateManager.cs
- NamedObject.cs
- ListControl.cs
- TransformerInfo.cs
- SimpleWorkerRequest.cs
- InvalidComObjectException.cs
- AppDomainProtocolHandler.cs
- ServiceBehaviorElementCollection.cs
- ActivityTypeDesigner.xaml.cs
- FormsAuthenticationUser.cs
- CommunicationObjectManager.cs
- ConnectionPoolRegistry.cs
- PointCollection.cs
- NameValueCollection.cs
- ContextToken.cs
- FlowDocumentPaginator.cs
- StdValidatorsAndConverters.cs
- CircleHotSpot.cs
- SimpleBitVector32.cs
- ColumnCollectionEditor.cs
- Psha1DerivedKeyGenerator.cs
- SerializerProvider.cs
- SqlConnectionFactory.cs
- BCLDebug.cs
- GridViewPageEventArgs.cs
- SourceElementsCollection.cs
- Axis.cs
- SqlDataAdapter.cs
- RowParagraph.cs
- ReverseInheritProperty.cs
- XhtmlBasicPhoneCallAdapter.cs
- ConditionalAttribute.cs
- ManagedCodeMarkers.cs
- ColorPalette.cs
- HashSetDebugView.cs
- SharedPerformanceCounter.cs
- UnsafeMethods.cs
- KeyNotFoundException.cs
- Unit.cs
- CacheAxisQuery.cs
- EditorAttribute.cs
- HttpVersion.cs
- RuntimeConfigurationRecord.cs
- WhitespaceRuleReader.cs
- ConstraintStruct.cs
- PropertyTab.cs
- CharConverter.cs
- Ipv6Element.cs
- BigIntegerStorage.cs
- ValidateNames.cs
- ClientSettingsProvider.cs
- TextTreeExtractElementUndoUnit.cs
- PropertyItem.cs
- SqlAliasesReferenced.cs
- ClientUtils.cs
- WebPartConnection.cs
- DataSourceCache.cs
- X509CertificateClaimSet.cs
- SystemTcpConnection.cs
- TableParaClient.cs
- DataStreamFromComStream.cs
- SelectedPathEditor.cs
- InputBindingCollection.cs
- DataGridViewHitTestInfo.cs
- CommonDialog.cs
- OleDbSchemaGuid.cs
- DataGridCellItemAutomationPeer.cs
- ContentElement.cs
- XmlTextAttribute.cs
- SqlParameter.cs