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
- HttpClientCertificate.cs
- InlineUIContainer.cs
- ReadWriteObjectLock.cs
- MultiPageTextView.cs
- PropertyDescriptor.cs
- CompiledQueryCacheEntry.cs
- OrderedEnumerableRowCollection.cs
- arabicshape.cs
- BitmapVisualManager.cs
- Documentation.cs
- DataComponentGenerator.cs
- NavigationProperty.cs
- ToolStripPanelRenderEventArgs.cs
- DynamicArgumentDialog.cs
- PagesChangedEventArgs.cs
- Accessible.cs
- CancellationHandlerDesigner.cs
- AmbientValueAttribute.cs
- LogRestartAreaEnumerator.cs
- TagMapInfo.cs
- AppDomainProtocolHandler.cs
- UrlRoutingHandler.cs
- DirectoryObjectSecurity.cs
- AdRotator.cs
- XmlReflectionImporter.cs
- TextBox.cs
- UDPClient.cs
- UtilityExtension.cs
- CodeNamespaceCollection.cs
- EntityDataSourceUtil.cs
- CmsInterop.cs
- DiffuseMaterial.cs
- CmsUtils.cs
- DataBoundControl.cs
- SafeArrayTypeMismatchException.cs
- CultureInfoConverter.cs
- WebControl.cs
- CompositeActivityValidator.cs
- EntityViewContainer.cs
- LocalFileSettingsProvider.cs
- ManipulationCompletedEventArgs.cs
- LocalizationParserHooks.cs
- RemotingConfiguration.cs
- FileCodeGroup.cs
- HMACMD5.cs
- LoginAutoFormat.cs
- AbandonedMutexException.cs
- Oid.cs
- PolicyManager.cs
- HistoryEventArgs.cs
- SmiConnection.cs
- QuaternionConverter.cs
- ToolStripRenderer.cs
- Point3DAnimation.cs
- PolyLineSegmentFigureLogic.cs
- MarkupCompiler.cs
- AccessorTable.cs
- CounterCreationDataCollection.cs
- InternalPermissions.cs
- AddInIpcChannel.cs
- HashSetDebugView.cs
- MenuEventArgs.cs
- SystemDiagnosticsSection.cs
- PathGeometry.cs
- CommandEventArgs.cs
- WorkflowRuntimeService.cs
- EntityTransaction.cs
- MarshalDirectiveException.cs
- ToolStripPanelRenderEventArgs.cs
- WebColorConverter.cs
- ContentType.cs
- HashCodeCombiner.cs
- Vector.cs
- TaskFormBase.cs
- UInt32.cs
- ProgressBarAutomationPeer.cs
- QueryExpr.cs
- TableRowGroupCollection.cs
- ExeConfigurationFileMap.cs
- ContextProperty.cs
- InvokeDelegate.cs
- ModifiableIteratorCollection.cs
- PerfCounters.cs
- WindowsListViewScroll.cs
- CmsInterop.cs
- ToolboxItemLoader.cs
- DataControlCommands.cs
- ProviderCommandInfoUtils.cs
- InputLanguage.cs
- OdbcReferenceCollection.cs
- WebPartActionVerb.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- DefinitionProperties.cs
- Documentation.cs
- JsonServiceDocumentSerializer.cs
- TextRangeAdaptor.cs
- InstalledFontCollection.cs
- EncoderParameters.cs
- WorkflowTimerService.cs
- SiteMapNode.cs