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
- SevenBitStream.cs
- RbTree.cs
- WindowsListView.cs
- mediaclock.cs
- MouseOverProperty.cs
- DataControlCommands.cs
- DirectoryLocalQuery.cs
- XmlException.cs
- _NetRes.cs
- ProfilePropertyMetadata.cs
- Lease.cs
- EdmFunction.cs
- NetDataContractSerializer.cs
- Effect.cs
- adornercollection.cs
- DescendentsWalker.cs
- EntityDataReader.cs
- ChangeBlockUndoRecord.cs
- StringStorage.cs
- SymbolEqualComparer.cs
- XmlSerializerVersionAttribute.cs
- AutoCompleteStringCollection.cs
- XmlEventCache.cs
- NamedPipeChannelFactory.cs
- SrgsRuleRef.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- SqlCacheDependencySection.cs
- Storyboard.cs
- PropertyConverter.cs
- DiffuseMaterial.cs
- LogicalCallContext.cs
- CheckBox.cs
- TableLayoutSettings.cs
- CatalogPart.cs
- X509Certificate2Collection.cs
- XsltFunctions.cs
- TrackingMemoryStream.cs
- Misc.cs
- PiiTraceSource.cs
- XmlWriterTraceListener.cs
- PaginationProgressEventArgs.cs
- UpdateCompiler.cs
- EventLogPermissionEntry.cs
- BinHexEncoder.cs
- SoapProtocolReflector.cs
- tooltip.cs
- AsyncStreamReader.cs
- GAC.cs
- ReadOnlyDataSourceView.cs
- EntityContainerEntitySet.cs
- DoubleLink.cs
- SemanticKeyElement.cs
- CodeThrowExceptionStatement.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- TreeNodeCollectionEditorDialog.cs
- HiddenField.cs
- WhitespaceRuleLookup.cs
- ComboBox.cs
- WebBrowserHelper.cs
- __Error.cs
- DoubleCollectionValueSerializer.cs
- DefaultSettingsSection.cs
- TrustLevelCollection.cs
- HijriCalendar.cs
- GridViewRow.cs
- XPathNavigatorReader.cs
- ListViewItem.cs
- DoubleKeyFrameCollection.cs
- ObjectDisposedException.cs
- DataObjectPastingEventArgs.cs
- DataBoundControl.cs
- Paragraph.cs
- StrongNameUtility.cs
- FormsAuthenticationEventArgs.cs
- XpsS0ValidatingLoader.cs
- ThousandthOfEmRealDoubles.cs
- AddInStore.cs
- Geometry3D.cs
- ContentDisposition.cs
- updateconfighost.cs
- InfoCardSymmetricAlgorithm.cs
- ScrollChangedEventArgs.cs
- BinaryWriter.cs
- Transform3DGroup.cs
- Rect3DConverter.cs
- ReadContentAsBinaryHelper.cs
- Label.cs
- TextRangeAdaptor.cs
- OleDbParameterCollection.cs
- DataGridViewToolTip.cs
- OleDbWrapper.cs
- Html32TextWriter.cs
- JsonWriterDelegator.cs
- ActiveXSite.cs
- TextControlDesigner.cs
- MessageQueueKey.cs
- LinqDataSourceContextEventArgs.cs
- FtpWebResponse.cs
- RepeaterItemCollection.cs
- EnterpriseServicesHelper.cs