Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- TimeManager.cs
- Helpers.cs
- OutOfProcStateClientManager.cs
- PropertyStore.cs
- SecuritySessionServerSettings.cs
- PerformanceCounterPermissionEntry.cs
- QilInvoke.cs
- RelatedEnd.cs
- MetaType.cs
- EventHandlersDesigner.cs
- MessagePartDescription.cs
- LinearGradientBrush.cs
- SmiMetaDataProperty.cs
- BridgeDataRecord.cs
- PeerNameResolver.cs
- HttpPostedFile.cs
- WrappedIUnknown.cs
- EncodingStreamWrapper.cs
- validation.cs
- CodeObjectCreateExpression.cs
- _ListenerAsyncResult.cs
- StylusPlugin.cs
- ManagedIStream.cs
- ButtonChrome.cs
- KnownTypes.cs
- AutomationPropertyInfo.cs
- BrowserCapabilitiesCodeGenerator.cs
- NetworkInformationPermission.cs
- XPathSingletonIterator.cs
- HttpWebResponse.cs
- _SslSessionsCache.cs
- TreeNodeCollection.cs
- WorkflowMarkupSerializationManager.cs
- RectAnimationClockResource.cs
- Model3DGroup.cs
- Registry.cs
- RandomDelayQueuedSendsAsyncResult.cs
- Serializer.cs
- METAHEADER.cs
- MouseActionValueSerializer.cs
- EventDescriptor.cs
- ListCollectionView.cs
- CssClassPropertyAttribute.cs
- Delegate.cs
- SharedConnectionInfo.cs
- SecurityTokenException.cs
- CharacterMetrics.cs
- ReadOnlyDictionary.cs
- ModuleBuilder.cs
- RemoteWebConfigurationHostStream.cs
- UrlAuthorizationModule.cs
- HttpGetServerProtocol.cs
- ToolStripGripRenderEventArgs.cs
- PerformanceCounterPermissionAttribute.cs
- COM2PropertyPageUITypeConverter.cs
- columnmapkeybuilder.cs
- FirstMatchCodeGroup.cs
- _Rfc2616CacheValidators.cs
- PropertySegmentSerializer.cs
- DiscreteKeyFrames.cs
- ValueQuery.cs
- VisualBasicHelper.cs
- UnsafeNativeMethods.cs
- PriorityBindingExpression.cs
- ColumnMapProcessor.cs
- ProcessModelInfo.cs
- TreeIterator.cs
- TextRangeEditLists.cs
- MaskInputRejectedEventArgs.cs
- ReferentialConstraint.cs
- CookieHandler.cs
- Sequence.cs
- AuthenticationSection.cs
- DynamicRouteExpression.cs
- Image.cs
- FormViewDesigner.cs
- WebPartConnectionsConnectVerb.cs
- VisualStyleTypesAndProperties.cs
- ConfigXmlCDataSection.cs
- DataTrigger.cs
- ContractSearchPattern.cs
- SQLUtility.cs
- ObjectKeyFrameCollection.cs
- XmlSchemaComplexContentRestriction.cs
- ToolstripProfessionalRenderer.cs
- HttpListenerPrefixCollection.cs
- ButtonChrome.cs
- IncrementalReadDecoders.cs
- DirectoryInfo.cs
- RealProxy.cs
- BufferModeSettings.cs
- IPHostEntry.cs
- AddIn.cs
- X509ScopedServiceCertificateElementCollection.cs
- ToolStripContainer.cs
- SafeBitVector32.cs
- _SingleItemRequestCache.cs
- ActivityExecutorOperation.cs
- SelectionGlyphBase.cs
- DataGridColumnEventArgs.cs