Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / Media / ColorContextHelper.cs / 1544694 / ColorContextHelper.cs
//------------------------------------------------------------------------------ // Microsoft Windows Client Platform // Copyright (c) Microsoft Corporation, 2001, 2002, 2003 // // File: ColorContextHelper.cs //----------------------------------------------------------------------------- using System; using System.IO; using System.Runtime.InteropServices; using System.Windows.Media; using System.Windows.Media.Imaging; using MS.Internal; using MS.Win32; using System.Security; using System.Security.Permissions; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Reflection; using System.Diagnostics; using System.Globalization; using Microsoft.Win32.SafeHandles; using SR=MS.Internal.PresentationCore.SR; using SRID=MS.Internal.PresentationCore.SRID; using UnsafeNativeMethodsMilCoreApi=MS.Win32.PresentationCore.UnsafeNativeMethods; namespace System.Windows.Media { #region SafeProfileHandle internal class SafeProfileHandle : SafeHandleZeroOrMinusOneIsInvalid { ////// Use this constructor if the handle exists at construction time. /// ////// Critical: The ctor of the base class requires SecurityPermission /// [SecurityCritical] internal SafeProfileHandle() : base(true) { } ////// Use this constructor if the handle exists at construction time. /// ////// Critical: The ctor of the base class requires SecurityPermission /// This code calls SetHandle /// [SecurityCritical] internal SafeProfileHandle(IntPtr profile) : base(true) { SetHandle(profile); } ////// Critical - calls unmanaged code, not treat as safe because you must /// validate that handle is a valid color context handle. /// [SecurityCritical] protected override bool ReleaseHandle() { return UnsafeNativeMethodsMilCoreApi.Mscms.CloseColorProfile(handle); } } #endregion #region ColorContextHelper ////// Helper struct to call into MSCMS color context APIs /// internal struct ColorContextHelper { /// Opens a color profile. /// /// NOTE: This may fail. It is up to the caller to handle it by checking IsInvalid. /// ////// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data. /// [SecurityCritical] internal void OpenColorProfile(ref UnsafeNativeMethods.PROFILE profile) { // No need to get rid of the old handle as it will get GC'ed _profileHandle = UnsafeNativeMethodsMilCoreApi.Mscms.OpenColorProfile( ref profile, NativeMethods.PROFILE_READ, // DesiredAccess NativeMethods.FILE_SHARE_READ, // ShareMode NativeMethods.OPEN_EXISTING // CreationMode ); } /// Retrieves the profile header /// /// /// NOTE: This may fail. It is up to the caller to handle it by checking the bool. /// ////// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data. /// [SecurityCritical] internal bool GetColorProfileHeader(out UnsafeNativeMethods.PROFILEHEADER header) { if (IsInvalid) { throw new InvalidOperationException(SR.Get(SRID.Image_ColorContextInvalid)); } return UnsafeNativeMethodsMilCoreApi.Mscms.GetColorProfileHeader(_profileHandle, out header); } /// Retrieves the color profile from handle ////// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data. /// [SecurityCritical] internal void GetColorProfileFromHandle(byte[] buffer, ref uint bufferSize) { Invariant.Assert(buffer == null || bufferSize <= buffer.Length); if (IsInvalid) { throw new InvalidOperationException(SR.Get(SRID.Image_ColorContextInvalid)); } // If the buffer is null, this function will return FALSE because it didn't actually copy anything. That's fine and that's // what we want. if (!UnsafeNativeMethodsMilCoreApi.Mscms.GetColorProfileFromHandle(_profileHandle, buffer, ref bufferSize) && buffer != null) { HRESULT.Check(Marshal.GetHRForLastWin32Error()); } } ////// Critical - Accesses critical resource _profileHandle /// TreatAsSafe - No inputs and just checks if SafeHandle is valid or not. /// internal bool IsInvalid { [SecurityCritical, SecurityTreatAsSafe] get { return _profileHandle == null || _profileHandle.IsInvalid; } } ////// ProfileHandle /// ////// SecurityCritical: This comes out of an elevation needs to be critical and tracked. /// internal SafeProfileHandle ProfileHandle { [SecurityCritical] get { return _profileHandle; } } #region Data members ////// SecurityCritical: This comes out of an elevation needs to be critical and tracked. /// [SecurityCritical] SafeProfileHandle _profileHandle; #endregion } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ // Microsoft Windows Client Platform // Copyright (c) Microsoft Corporation, 2001, 2002, 2003 // // File: ColorContextHelper.cs //----------------------------------------------------------------------------- using System; using System.IO; using System.Runtime.InteropServices; using System.Windows.Media; using System.Windows.Media.Imaging; using MS.Internal; using MS.Win32; using System.Security; using System.Security.Permissions; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Reflection; using System.Diagnostics; using System.Globalization; using Microsoft.Win32.SafeHandles; using SR=MS.Internal.PresentationCore.SR; using SRID=MS.Internal.PresentationCore.SRID; using UnsafeNativeMethodsMilCoreApi=MS.Win32.PresentationCore.UnsafeNativeMethods; namespace System.Windows.Media { #region SafeProfileHandle internal class SafeProfileHandle : SafeHandleZeroOrMinusOneIsInvalid { ////// Use this constructor if the handle exists at construction time. /// ////// Critical: The ctor of the base class requires SecurityPermission /// [SecurityCritical] internal SafeProfileHandle() : base(true) { } ////// Use this constructor if the handle exists at construction time. /// ////// Critical: The ctor of the base class requires SecurityPermission /// This code calls SetHandle /// [SecurityCritical] internal SafeProfileHandle(IntPtr profile) : base(true) { SetHandle(profile); } ////// Critical - calls unmanaged code, not treat as safe because you must /// validate that handle is a valid color context handle. /// [SecurityCritical] protected override bool ReleaseHandle() { return UnsafeNativeMethodsMilCoreApi.Mscms.CloseColorProfile(handle); } } #endregion #region ColorContextHelper ////// Helper struct to call into MSCMS color context APIs /// internal struct ColorContextHelper { /// Opens a color profile. /// /// NOTE: This may fail. It is up to the caller to handle it by checking IsInvalid. /// ////// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data. /// [SecurityCritical] internal void OpenColorProfile(ref UnsafeNativeMethods.PROFILE profile) { // No need to get rid of the old handle as it will get GC'ed _profileHandle = UnsafeNativeMethodsMilCoreApi.Mscms.OpenColorProfile( ref profile, NativeMethods.PROFILE_READ, // DesiredAccess NativeMethods.FILE_SHARE_READ, // ShareMode NativeMethods.OPEN_EXISTING // CreationMode ); } /// Retrieves the profile header /// /// /// NOTE: This may fail. It is up to the caller to handle it by checking the bool. /// ////// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data. /// [SecurityCritical] internal bool GetColorProfileHeader(out UnsafeNativeMethods.PROFILEHEADER header) { if (IsInvalid) { throw new InvalidOperationException(SR.Get(SRID.Image_ColorContextInvalid)); } return UnsafeNativeMethodsMilCoreApi.Mscms.GetColorProfileHeader(_profileHandle, out header); } /// Retrieves the color profile from handle ////// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data. /// [SecurityCritical] internal void GetColorProfileFromHandle(byte[] buffer, ref uint bufferSize) { Invariant.Assert(buffer == null || bufferSize <= buffer.Length); if (IsInvalid) { throw new InvalidOperationException(SR.Get(SRID.Image_ColorContextInvalid)); } // If the buffer is null, this function will return FALSE because it didn't actually copy anything. That's fine and that's // what we want. if (!UnsafeNativeMethodsMilCoreApi.Mscms.GetColorProfileFromHandle(_profileHandle, buffer, ref bufferSize) && buffer != null) { HRESULT.Check(Marshal.GetHRForLastWin32Error()); } } ////// Critical - Accesses critical resource _profileHandle /// TreatAsSafe - No inputs and just checks if SafeHandle is valid or not. /// internal bool IsInvalid { [SecurityCritical, SecurityTreatAsSafe] get { return _profileHandle == null || _profileHandle.IsInvalid; } } ////// ProfileHandle /// ////// SecurityCritical: This comes out of an elevation needs to be critical and tracked. /// internal SafeProfileHandle ProfileHandle { [SecurityCritical] get { return _profileHandle; } } #region Data members ////// SecurityCritical: This comes out of an elevation needs to be critical and tracked. /// [SecurityCritical] SafeProfileHandle _profileHandle; #endregion } #endregion } // 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
- unsafeIndexingFilterStream.cs
- SoapCodeExporter.cs
- WindowHideOrCloseTracker.cs
- DbConnectionPoolGroup.cs
- NameValuePair.cs
- BinaryOperationBinder.cs
- CompilationRelaxations.cs
- FrameworkContextData.cs
- XmlCodeExporter.cs
- JavaScriptString.cs
- PackWebRequestFactory.cs
- HttpPostLocalhostServerProtocol.cs
- SystemGatewayIPAddressInformation.cs
- SizeConverter.cs
- TraceHwndHost.cs
- PropertyEmitterBase.cs
- PropertyGridCommands.cs
- PeekCompletedEventArgs.cs
- PropertyGridEditorPart.cs
- QueryExpr.cs
- SQLMembershipProvider.cs
- PageSetupDialog.cs
- TextDecorationCollection.cs
- StreamSecurityUpgradeAcceptor.cs
- PointConverter.cs
- GeometryGroup.cs
- BitmapEffectvisualstate.cs
- FormViewCommandEventArgs.cs
- AnnotationComponentManager.cs
- DetailsViewUpdatedEventArgs.cs
- ExpressionBuilderCollection.cs
- _IPv4Address.cs
- ContainerVisual.cs
- webproxy.cs
- DispatchWrapper.cs
- XmlSchemaValidator.cs
- Parameter.cs
- VirtualizingPanel.cs
- MediaEntryAttribute.cs
- ThicknessKeyFrameCollection.cs
- Inline.cs
- ProxyHwnd.cs
- Font.cs
- QilCloneVisitor.cs
- TextEditorDragDrop.cs
- DataGridColumn.cs
- PseudoWebRequest.cs
- Int32CAMarshaler.cs
- ConfigXmlCDataSection.cs
- WebBrowserProgressChangedEventHandler.cs
- ConfigPathUtility.cs
- HTTPNotFoundHandler.cs
- RangeValidator.cs
- ImageSourceValueSerializer.cs
- Win32MouseDevice.cs
- PlatformNotSupportedException.cs
- PreviewPrintController.cs
- ColumnResult.cs
- PartialCachingControl.cs
- RegionIterator.cs
- Ref.cs
- HotSpotCollection.cs
- CodeDOMUtility.cs
- HttpAsyncResult.cs
- TrustLevel.cs
- ClientUtils.cs
- HostSecurityManager.cs
- XamlParser.cs
- SessionEndingCancelEventArgs.cs
- ACL.cs
- SoapIgnoreAttribute.cs
- PersistenceIOParticipant.cs
- SocketConnection.cs
- _Rfc2616CacheValidators.cs
- FontFaceLayoutInfo.cs
- CodeConditionStatement.cs
- SizeAnimationUsingKeyFrames.cs
- DummyDataSource.cs
- View.cs
- RelationshipManager.cs
- EntityWrapperFactory.cs
- SchemaManager.cs
- _AutoWebProxyScriptWrapper.cs
- NullRuntimeConfig.cs
- UInt16Storage.cs
- XpsFixedDocumentReaderWriter.cs
- ConstructorExpr.cs
- ColumnCollection.cs
- BinaryCommonClasses.cs
- EdmFunction.cs
- XmlAnyAttributeAttribute.cs
- SystemUdpStatistics.cs
- OracleParameterBinding.cs
- ExternalFile.cs
- UpdatePanelTriggerCollection.cs
- MarkupExtensionParser.cs
- SqlFlattener.cs
- ObjectDataSourceView.cs
- Selector.cs
- SoapObjectWriter.cs