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
- AssemblyBuilder.cs
- PageHandlerFactory.cs
- ConfigXmlAttribute.cs
- PerformanceCounterPermissionEntryCollection.cs
- SqlDataSourceConnectionPanel.cs
- ValidationSummary.cs
- ValidationRule.cs
- CheckBoxField.cs
- BinaryFormatter.cs
- SafeBitVector32.cs
- Process.cs
- EncoderNLS.cs
- TrackBar.cs
- DesignerActionMethodItem.cs
- RelationshipSet.cs
- AsymmetricAlgorithm.cs
- ButtonRenderer.cs
- MetadataUtilsSmi.cs
- ValidatingReaderNodeData.cs
- GcHandle.cs
- DBConnection.cs
- FixedSOMContainer.cs
- InkCanvasAutomationPeer.cs
- GeometryConverter.cs
- XmlSchemaComplexContent.cs
- _HeaderInfoTable.cs
- HtmlInputSubmit.cs
- ChameleonKey.cs
- BaseResourcesBuildProvider.cs
- XmlDictionaryReaderQuotas.cs
- RelatedPropertyManager.cs
- RepeaterItem.cs
- DataGridBoolColumn.cs
- TrackingStringDictionary.cs
- TranslateTransform3D.cs
- ImplicitInputBrush.cs
- Guid.cs
- TitleStyle.cs
- ContractMapping.cs
- DataGridViewColumn.cs
- DataGridComponentEditor.cs
- _OSSOCK.cs
- ObsoleteAttribute.cs
- NegatedCellConstant.cs
- GroupBoxRenderer.cs
- FileSecurity.cs
- WaitHandle.cs
- Propagator.cs
- XpsFixedPageReaderWriter.cs
- StaticExtension.cs
- InvalidAsynchronousStateException.cs
- PrimitiveXmlSerializers.cs
- WasEndpointConfigContainer.cs
- ObjectDataSourceFilteringEventArgs.cs
- StackSpiller.cs
- File.cs
- DependencyPropertyConverter.cs
- Lookup.cs
- ErrorFormatter.cs
- CodeAttachEventStatement.cs
- PropagatorResult.cs
- IUnknownConstantAttribute.cs
- XamlReaderHelper.cs
- XomlDesignerLoader.cs
- Wildcard.cs
- NumberFunctions.cs
- MarginsConverter.cs
- StrokeNodeOperations2.cs
- _TimerThread.cs
- JapaneseCalendar.cs
- RoleManagerModule.cs
- DataGridViewCellValueEventArgs.cs
- SetStoryboardSpeedRatio.cs
- TransformCollection.cs
- Zone.cs
- WebService.cs
- Matrix.cs
- SplashScreen.cs
- ConstructorNeedsTagAttribute.cs
- SqlServer2KCompatibilityCheck.cs
- DataContractSerializerOperationBehavior.cs
- PackWebResponse.cs
- ChtmlTextWriter.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- Operand.cs
- PreloadHost.cs
- AttachmentCollection.cs
- LocalFileSettingsProvider.cs
- ExpressionNormalizer.cs
- XmlLoader.cs
- ReadOnlyHierarchicalDataSourceView.cs
- PointLightBase.cs
- BaseAsyncResult.cs
- MSAANativeProvider.cs
- _Semaphore.cs
- NumericUpDown.cs
- StylusPointProperty.cs
- NameValuePermission.cs
- WindowCollection.cs
- SqlDataSource.cs