Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- ValidationResult.cs
- RenderDataDrawingContext.cs
- Win32.cs
- BlurEffect.cs
- EntityDataSourceQueryBuilder.cs
- SqlCrossApplyToCrossJoin.cs
- RuntimeHandles.cs
- XamlClipboardData.cs
- FileRegion.cs
- Msec.cs
- DataServiceException.cs
- ResourceReferenceExpressionConverter.cs
- UTF32Encoding.cs
- DBConnection.cs
- OpenTypeLayoutCache.cs
- DataContractSerializerElement.cs
- ResourceDescriptionAttribute.cs
- ProcessThreadCollection.cs
- CacheDependency.cs
- PersonalizableAttribute.cs
- SerializationAttributes.cs
- TableLayout.cs
- CodeSubDirectory.cs
- SystemKeyConverter.cs
- MgmtConfigurationRecord.cs
- DownloadProgressEventArgs.cs
- SimpleRecyclingCache.cs
- InkCollectionBehavior.cs
- MenuDesigner.cs
- DecoderBestFitFallback.cs
- MatrixUtil.cs
- XmlNodeWriter.cs
- VectorAnimationBase.cs
- RegexGroupCollection.cs
- BmpBitmapDecoder.cs
- ZoomingMessageFilter.cs
- SymbolMethod.cs
- RadioButtonStandardAdapter.cs
- Byte.cs
- DeferredReference.cs
- StringCollectionEditor.cs
- WebPartsSection.cs
- XmlMtomWriter.cs
- ConfigurationManagerInternal.cs
- SqlWebEventProvider.cs
- ColorIndependentAnimationStorage.cs
- ProviderSettingsCollection.cs
- TimeSpanConverter.cs
- NullableIntSumAggregationOperator.cs
- DBConcurrencyException.cs
- Attribute.cs
- XmlAtomicValue.cs
- TerminatorSinks.cs
- SoapReflector.cs
- GeneralTransform3D.cs
- CultureInfoConverter.cs
- Figure.cs
- TickBar.cs
- RemoteWebConfigurationHostStream.cs
- MouseGesture.cs
- NodeInfo.cs
- TypeElement.cs
- ComplexBindingPropertiesAttribute.cs
- infer.cs
- Typeface.cs
- TypedRowGenerator.cs
- SystemTcpConnection.cs
- TypefaceCollection.cs
- EmbeddedMailObjectCollectionEditor.cs
- ProcessThread.cs
- OracleCommand.cs
- _ListenerRequestStream.cs
- DbConnectionInternal.cs
- UnsafeNativeMethods.cs
- HandleScope.cs
- EditorReuseAttribute.cs
- DnsPermission.cs
- SQLGuidStorage.cs
- ToolBarTray.cs
- HelpProvider.cs
- ArraySet.cs
- ArrayTypeMismatchException.cs
- ObjectDataProvider.cs
- HtmlTable.cs
- TextTreeInsertUndoUnit.cs
- CacheMemory.cs
- DeviceContexts.cs
- QueryGenerator.cs
- SrgsGrammarCompiler.cs
- SqlGenericUtil.cs
- SortQuery.cs
- CircleHotSpot.cs
- ColumnWidthChangedEvent.cs
- XsltException.cs
- UInt64.cs
- Model3D.cs
- DataBindingHandlerAttribute.cs
- NativeMethods.cs
- SchemaTypeEmitter.cs
- DesignerCatalogPartChrome.cs