Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Core / CSharp / System / Windows / Media / ColorContextHelper.cs / 1 / 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 UnsafeNativeMethods=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()
{
if (!UnsafeNativeMethods.Mscms.CloseColorProfile(handle))
{
HRESULT.Check(Marshal.GetHRForLastWin32Error());
}
return true;
}
}
#endregion
#region ColorContextHelper
///
/// Class to call into MSCMS color context APIs
///
internal class ColorContextHelper
{
/// Constructor
internal ColorContextHelper()
{
}
/// Opens a color profile
///
/// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data.
///
[SecurityCritical]
internal void OpenColorProfile(IntPtr pProfile)
{
// No need to get rid of the old handle as it will get GC'ed
_profileHandle = UnsafeNativeMethods.Mscms.OpenColorProfile(
pProfile,
NativeMethods.PROFILE_READ, // DesiredAccess
NativeMethods.FILE_SHARE_READ, // ShareMode
NativeMethods.OPEN_EXISTING // CreationMode
);
if (_profileHandle == null || _profileHandle.IsInvalid)
{
HRESULT.Check(Marshal.GetHRForLastWin32Error());
}
}
/// Retrieves the profile header
///
/// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data.
///
[SecurityCritical]
internal void GetColorProfileHeader(IntPtr pHeader)
{
if (_profileHandle == null || _profileHandle.IsInvalid)
{
throw new InvalidOperationException(SR.Get(SRID.Image_ColorContextInvalid));
}
HRESULT.Check(UnsafeNativeMethods.Mscms.GetColorProfileHeader(_profileHandle, pHeader));
}
/// Retrieves the color profile from handle
///
/// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data.
///
[SecurityCritical]
internal void GetColorProfileFromHandle(IntPtr pBuffer, IntPtr pdwSize)
{
if (_profileHandle == null || _profileHandle.IsInvalid)
{
throw new InvalidOperationException(SR.Get(SRID.Image_ColorContextInvalid));
}
HRESULT.Check(UnsafeNativeMethods.Mscms.GetColorProfileFromHandle(_profileHandle, pBuffer, pdwSize));
}
///
/// 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 UnsafeNativeMethods=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()
{
if (!UnsafeNativeMethods.Mscms.CloseColorProfile(handle))
{
HRESULT.Check(Marshal.GetHRForLastWin32Error());
}
return true;
}
}
#endregion
#region ColorContextHelper
///
/// Class to call into MSCMS color context APIs
///
internal class ColorContextHelper
{
/// Constructor
internal ColorContextHelper()
{
}
/// Opens a color profile
///
/// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data.
///
[SecurityCritical]
internal void OpenColorProfile(IntPtr pProfile)
{
// No need to get rid of the old handle as it will get GC'ed
_profileHandle = UnsafeNativeMethods.Mscms.OpenColorProfile(
pProfile,
NativeMethods.PROFILE_READ, // DesiredAccess
NativeMethods.FILE_SHARE_READ, // ShareMode
NativeMethods.OPEN_EXISTING // CreationMode
);
if (_profileHandle == null || _profileHandle.IsInvalid)
{
HRESULT.Check(Marshal.GetHRForLastWin32Error());
}
}
/// Retrieves the profile header
///
/// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data.
///
[SecurityCritical]
internal void GetColorProfileHeader(IntPtr pHeader)
{
if (_profileHandle == null || _profileHandle.IsInvalid)
{
throw new InvalidOperationException(SR.Get(SRID.Image_ColorContextInvalid));
}
HRESULT.Check(UnsafeNativeMethods.Mscms.GetColorProfileHeader(_profileHandle, pHeader));
}
/// Retrieves the color profile from handle
///
/// SecurityCritical: Calls unmanaged code, accepts InPtr/unverified data.
///
[SecurityCritical]
internal void GetColorProfileFromHandle(IntPtr pBuffer, IntPtr pdwSize)
{
if (_profileHandle == null || _profileHandle.IsInvalid)
{
throw new InvalidOperationException(SR.Get(SRID.Image_ColorContextInvalid));
}
HRESULT.Check(UnsafeNativeMethods.Mscms.GetColorProfileFromHandle(_profileHandle, pBuffer, pdwSize));
}
///
/// 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
- VerificationException.cs
- CodeIndexerExpression.cs
- HttpServerUtilityBase.cs
- FixedSOMFixedBlock.cs
- XmlSchemaObject.cs
- SelectionProcessor.cs
- FixedSOMFixedBlock.cs
- DataSourceHelper.cs
- SignatureHelper.cs
- ReadContentAsBinaryHelper.cs
- DesignerHelpers.cs
- XmlSchemaSimpleTypeRestriction.cs
- XhtmlBasicPanelAdapter.cs
- ControlIdConverter.cs
- DbConnectionStringCommon.cs
- ShutDownListener.cs
- ThrowHelper.cs
- ObjectSpanRewriter.cs
- InlineCollection.cs
- CrossSiteScriptingValidation.cs
- TextAction.cs
- KeySpline.cs
- NamedObject.cs
- ConnectionStringSettingsCollection.cs
- GridViewColumn.cs
- XmlHelper.cs
- WebSysDisplayNameAttribute.cs
- AssociationType.cs
- BindingNavigatorDesigner.cs
- MarkedHighlightComponent.cs
- InputScope.cs
- SizeValueSerializer.cs
- FixedSOMElement.cs
- SystemException.cs
- TransformerTypeCollection.cs
- ActivityCollectionMarkupSerializer.cs
- DragDropHelper.cs
- TraversalRequest.cs
- XhtmlStyleClass.cs
- CompositeControl.cs
- FontStretches.cs
- GatewayDefinition.cs
- Pair.cs
- QuestionEventArgs.cs
- XamlFilter.cs
- PeerNameRecordCollection.cs
- SqlDataSourceCommandEventArgs.cs
- Container.cs
- isolationinterop.cs
- TableFieldsEditor.cs
- AbstractSvcMapFileLoader.cs
- FileUtil.cs
- BinaryObjectWriter.cs
- SoapAttributeAttribute.cs
- DropTarget.cs
- SQLRoleProvider.cs
- ConfigErrorGlyph.cs
- MiniParameterInfo.cs
- UserNameSecurityTokenAuthenticator.cs
- Matrix.cs
- XmlHierarchyData.cs
- TransformerInfo.cs
- ColorTransformHelper.cs
- ActivityScheduledRecord.cs
- LoginView.cs
- PrimaryKeyTypeConverter.cs
- GeneralTransform2DTo3D.cs
- DataMemberAttribute.cs
- InternalControlCollection.cs
- DisplayInformation.cs
- UITypeEditor.cs
- SelectionEditingBehavior.cs
- XmlCodeExporter.cs
- BasicViewGenerator.cs
- DetailsViewRowCollection.cs
- EntitySqlQueryBuilder.cs
- CompositeDuplexBindingElementImporter.cs
- HtmlAnchor.cs
- ListViewInsertEventArgs.cs
- DropSource.cs
- VBIdentifierNameEditor.cs
- MetadataWorkspace.cs
- TimeSpan.cs
- ToolTip.cs
- SpecularMaterial.cs
- PersonalizationProvider.cs
- ResourcesGenerator.cs
- OracleParameterCollection.cs
- SerializationException.cs
- ResponseBodyWriter.cs
- ChildTable.cs
- HttpRuntime.cs
- AttachedPropertyMethodSelector.cs
- IItemProperties.cs
- DesignRelation.cs
- DesignBindingConverter.cs
- DataRow.cs
- TrustManagerPromptUI.cs
- EntityContainerAssociationSet.cs
- SelectedGridItemChangedEvent.cs