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
- WindowsPrincipal.cs
- SynchronizationContext.cs
- Subtree.cs
- HtmlPageAdapter.cs
- Tracking.cs
- MbpInfo.cs
- SafeArrayTypeMismatchException.cs
- TemplateInstanceAttribute.cs
- InputLanguageSource.cs
- oledbconnectionstring.cs
- XmlNamespaceManager.cs
- SqlTypeSystemProvider.cs
- SystemWebSectionGroup.cs
- iisPickupDirectory.cs
- Binding.cs
- RolePrincipal.cs
- WaitHandleCannotBeOpenedException.cs
- OneToOneMappingSerializer.cs
- filewebresponse.cs
- Version.cs
- WmlObjectListAdapter.cs
- ImpersonationContext.cs
- ToolStripPanelRenderEventArgs.cs
- DropShadowEffect.cs
- pingexception.cs
- XsltSettings.cs
- HwndAppCommandInputProvider.cs
- EpmTargetTree.cs
- ObjectDisposedException.cs
- IteratorDescriptor.cs
- NetworkAddressChange.cs
- PopupRoot.cs
- BehaviorEditorPart.cs
- StorageComplexPropertyMapping.cs
- FlowDocumentReader.cs
- SecurityCriticalDataForSet.cs
- FamilyTypefaceCollection.cs
- ThumbButtonInfo.cs
- XpsImageSerializationService.cs
- AuthorizationSection.cs
- EventLogPermission.cs
- TransactionFilter.cs
- FontEmbeddingManager.cs
- CodeAttributeArgument.cs
- FilteredReadOnlyMetadataCollection.cs
- RequestStatusBarUpdateEventArgs.cs
- ScriptingScriptResourceHandlerSection.cs
- IEnumerable.cs
- SRef.cs
- ModifiableIteratorCollection.cs
- MemoryFailPoint.cs
- COM2DataTypeToManagedDataTypeConverter.cs
- BindToObject.cs
- ZipQueryOperator.cs
- CopyOnWriteList.cs
- EmulateRecognizeCompletedEventArgs.cs
- SettingsPropertyValue.cs
- DecoderFallback.cs
- HttpValueCollection.cs
- ResourceAttributes.cs
- QilInvoke.cs
- iisPickupDirectory.cs
- MediaPlayerState.cs
- Completion.cs
- CompositeDataBoundControl.cs
- InvalidOleVariantTypeException.cs
- CodeParameterDeclarationExpression.cs
- FormClosingEvent.cs
- HandleRef.cs
- PostBackOptions.cs
- PageRequestManager.cs
- DataGridHeaderBorder.cs
- UnsafeNativeMethods.cs
- PrinterSettings.cs
- SchemaTypeEmitter.cs
- IFormattable.cs
- TogglePatternIdentifiers.cs
- DecimalAnimationUsingKeyFrames.cs
- CodeBlockBuilder.cs
- SerializationFieldInfo.cs
- PrintDialogException.cs
- SharedPerformanceCounter.cs
- RecordManager.cs
- RuntimeCompatibilityAttribute.cs
- InfiniteTimeSpanConverter.cs
- ProcessThreadDesigner.cs
- HoistedLocals.cs
- StreamUpdate.cs
- StatusBarPanelClickEvent.cs
- SystemTcpStatistics.cs
- XmlSchemaAnnotated.cs
- RuleConditionDialog.cs
- TagPrefixAttribute.cs
- UInt64Converter.cs
- ElementsClipboardData.cs
- PopOutPanel.cs
- SafeEventHandle.cs
- ControlUtil.cs
- HttpStreamXmlDictionaryWriter.cs
- DataBindingHandlerAttribute.cs