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

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ViewLoader.cs
- TableLayoutStyle.cs
- ClientType.cs
- returneventsaver.cs
- Literal.cs
- versioninfo.cs
- DocumentViewerBaseAutomationPeer.cs
- TextServicesProperty.cs
- RegexMatch.cs
- CngUIPolicy.cs
- TemplatedAdorner.cs
- ComplexPropertyEntry.cs
- SimpleBitVector32.cs
- ValueSerializer.cs
- HttpCapabilitiesSectionHandler.cs
- SecurityState.cs
- Form.cs
- ListViewGroup.cs
- CheckedPointers.cs
- BypassElementCollection.cs
- BaseProcessor.cs
- MsmqHostedTransportConfiguration.cs
- activationcontext.cs
- DetailsViewDeletedEventArgs.cs
- FatalException.cs
- DrawingContextDrawingContextWalker.cs
- DataGridTextBoxColumn.cs
- OleDbException.cs
- XmlSchemaAttributeGroupRef.cs
- SchemaElement.cs
- OleDbTransaction.cs
- XmlSchemaProviderAttribute.cs
- AudioFormatConverter.cs
- XmlKeywords.cs
- HttpFileCollection.cs
- PathSegmentCollection.cs
- HScrollProperties.cs
- DataControlImageButton.cs
- SiteMapPath.cs
- PageBreakRecord.cs
- RegistrationServices.cs
- AsnEncodedData.cs
- StickyNoteContentControl.cs
- LayoutUtils.cs
- TargetControlTypeCache.cs
- IndentTextWriter.cs
- ScriptingAuthenticationServiceSection.cs
- CodeCatchClauseCollection.cs
- SafeViewOfFileHandle.cs
- NumericUpDownAccelerationCollection.cs
- FormatConvertedBitmap.cs
- StandardTransformFactory.cs
- ConfigurationValidatorAttribute.cs
- DateRangeEvent.cs
- Authorization.cs
- QueryTaskGroupState.cs
- SqlLiftWhereClauses.cs
- PointLightBase.cs
- ObjectView.cs
- SwitchDesigner.xaml.cs
- ServiceModelConfigurationSection.cs
- UniqueConstraint.cs
- SynchronizationContext.cs
- DbParameterCollectionHelper.cs
- BindingGroup.cs
- MemoryStream.cs
- StringToken.cs
- GridViewCommandEventArgs.cs
- PathSegment.cs
- BitmapCodecInfo.cs
- SplitterCancelEvent.cs
- ChangeConflicts.cs
- XmlCodeExporter.cs
- ScrollProperties.cs
- PageThemeParser.cs
- RemotingAttributes.cs
- InputProviderSite.cs
- SqlBuffer.cs
- XmlWellformedWriter.cs
- httpapplicationstate.cs
- StorageScalarPropertyMapping.cs
- PerformanceCountersBase.cs
- InternalBufferOverflowException.cs
- SecurityElement.cs
- UserNameSecurityTokenParameters.cs
- ValueUtilsSmi.cs
- clipboard.cs
- WSSecurityOneDotOneReceiveSecurityHeader.cs
- Rfc2898DeriveBytes.cs
- PropertyDescriptorGridEntry.cs
- XmlDataSourceNodeDescriptor.cs
- ListViewSortEventArgs.cs
- FtpRequestCacheValidator.cs
- TemplateField.cs
- FixUpCollection.cs
- HtmlEncodedRawTextWriter.cs
- _SSPISessionCache.cs
- SecurityPermission.cs
- BinaryMethodMessage.cs
- DataException.cs