Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Core / CSharp / System / Windows / Media / SafeReversePInvokeHandle.cs / 1 / 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
- UIElement.cs
- Decorator.cs
- MLangCodePageEncoding.cs
- DataFieldConverter.cs
- TimerEventSubscriptionCollection.cs
- DataListCommandEventArgs.cs
- Table.cs
- UniqueConstraint.cs
- NumericUpDownAccelerationCollection.cs
- ToolStripDropDownButton.cs
- IpcClientChannel.cs
- AssociationEndMember.cs
- EncoderFallback.cs
- UnsettableComboBox.cs
- TemplateColumn.cs
- TypeInitializationException.cs
- InkPresenterAutomationPeer.cs
- FilterElement.cs
- PkcsUtils.cs
- securestring.cs
- FocusTracker.cs
- CollectionChange.cs
- FontEditor.cs
- ContainerUtilities.cs
- ArrangedElementCollection.cs
- Filter.cs
- returneventsaver.cs
- EntityDataSourceDesigner.cs
- AssemblyResourceLoader.cs
- SpecularMaterial.cs
- BidPrivateBase.cs
- PointLightBase.cs
- CellParagraph.cs
- BamlResourceSerializer.cs
- CheckBox.cs
- ObjectConverter.cs
- ControlEvent.cs
- UserNameSecurityToken.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- PagePropertiesChangingEventArgs.cs
- DataControlCommands.cs
- XPathNavigatorReader.cs
- XmlSchemaValidator.cs
- _CacheStreams.cs
- CancellationTokenSource.cs
- ClientProxyGenerator.cs
- SoapSchemaImporter.cs
- SwitchAttribute.cs
- EnlistmentTraceIdentifier.cs
- CodeSubDirectory.cs
- DataGridRowHeaderAutomationPeer.cs
- ComPlusThreadInitializer.cs
- HMACSHA256.cs
- HighContrastHelper.cs
- AdornedElementPlaceholder.cs
- _BasicClient.cs
- OperationAbortedException.cs
- BaseProcessor.cs
- ProfilePropertyNameValidator.cs
- SystemIPGlobalStatistics.cs
- IISMapPath.cs
- QueryStatement.cs
- DataServiceQueryContinuation.cs
- PrintEvent.cs
- DrawingContext.cs
- EntityDataSourceViewSchema.cs
- OLEDB_Util.cs
- ListViewTableRow.cs
- DataGridRelationshipRow.cs
- MostlySingletonList.cs
- baseshape.cs
- ResourceDefaultValueAttribute.cs
- SoapAttributes.cs
- TextEditorSpelling.cs
- TransactionChannelListener.cs
- MetadataItemSerializer.cs
- PointLight.cs
- NonParentingControl.cs
- XMLSyntaxException.cs
- Point3DCollectionValueSerializer.cs
- ElementInit.cs
- smtpconnection.cs
- XPathCompileException.cs
- BitmapPalettes.cs
- OutputCacheSettingsSection.cs
- Utility.cs
- StrongNameKeyPair.cs
- TemplateBuilder.cs
- EnumerableRowCollectionExtensions.cs
- UnsafeNativeMethods.cs
- DoubleLinkList.cs
- InternalControlCollection.cs
- XPathPatternParser.cs
- ErrorFormatterPage.cs
- TableRow.cs
- InternalsVisibleToAttribute.cs
- EditingScopeUndoUnit.cs
- TextLineBreak.cs
- ChineseLunisolarCalendar.cs
- CharacterHit.cs