Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / System / Diagnostics / Eventing / Reader / CoTaskMemSafeHandle.cs / 1305376 / CoTaskMemSafeHandle.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: CoTaskMemSafeHandle
**
** Purpose:
** This internal class is a SafeHandle implementation over a
** native CoTaskMem allocated via StringToCoTaskMemAuto.
**
============================================================*/
using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
namespace System.Diagnostics.Eventing.Reader {
//
// Marked as SecurityCritical due to link demands from inherited
// SafeHandle members.
//
#pragma warning disable 618 // Have not migrated to v4 transparency yet
[System.Security.SecurityCritical(System.Security.SecurityCriticalScope.Everything)]
#pragma warning restore 618
internal sealed class CoTaskMemSafeHandle : SafeHandle {
internal CoTaskMemSafeHandle()
: base(IntPtr.Zero, true) {
}
internal void SetMemory(IntPtr handle) {
SetHandle(handle);
}
internal IntPtr GetMemory() {
return handle;
}
public override bool IsInvalid {
get {
return IsClosed || handle == IntPtr.Zero;
}
}
protected override bool ReleaseHandle() {
Marshal.FreeCoTaskMem(handle);
handle = IntPtr.Zero;
return true;
}
//
// DONT compare CoTaskMemSafeHandle with CoTaskMemSafeHandle.Zero
// use IsInvalid instead. Zero is provided where a NULL handle needed
//
public static CoTaskMemSafeHandle Zero {
get {
return new CoTaskMemSafeHandle();
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: CoTaskMemSafeHandle
**
** Purpose:
** This internal class is a SafeHandle implementation over a
** native CoTaskMem allocated via StringToCoTaskMemAuto.
**
============================================================*/
using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
namespace System.Diagnostics.Eventing.Reader {
//
// Marked as SecurityCritical due to link demands from inherited
// SafeHandle members.
//
#pragma warning disable 618 // Have not migrated to v4 transparency yet
[System.Security.SecurityCritical(System.Security.SecurityCriticalScope.Everything)]
#pragma warning restore 618
internal sealed class CoTaskMemSafeHandle : SafeHandle {
internal CoTaskMemSafeHandle()
: base(IntPtr.Zero, true) {
}
internal void SetMemory(IntPtr handle) {
SetHandle(handle);
}
internal IntPtr GetMemory() {
return handle;
}
public override bool IsInvalid {
get {
return IsClosed || handle == IntPtr.Zero;
}
}
protected override bool ReleaseHandle() {
Marshal.FreeCoTaskMem(handle);
handle = IntPtr.Zero;
return true;
}
//
// DONT compare CoTaskMemSafeHandle with CoTaskMemSafeHandle.Zero
// use IsInvalid instead. Zero is provided where a NULL handle needed
//
public static CoTaskMemSafeHandle Zero {
get {
return new CoTaskMemSafeHandle();
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TextWriter.cs
- FormView.cs
- DebuggerAttributes.cs
- FontDifferentiator.cs
- SemaphoreFullException.cs
- ManagedFilter.cs
- SpeechUI.cs
- InvalidOperationException.cs
- SecurityToken.cs
- MeshGeometry3D.cs
- WindowsListViewGroup.cs
- UpdateProgress.cs
- DispatcherObject.cs
- PathTooLongException.cs
- RuntimeConfigLKG.cs
- AnnotationResource.cs
- indexingfiltermarshaler.cs
- WebPartEventArgs.cs
- _AcceptOverlappedAsyncResult.cs
- ResolveMatchesApril2005.cs
- FixedElement.cs
- SessionStateModule.cs
- EFDataModelProvider.cs
- DynamicRenderer.cs
- IntegerFacetDescriptionElement.cs
- SystemBrushes.cs
- SoapAttributeOverrides.cs
- ImageButton.cs
- StreamSecurityUpgradeInitiator.cs
- HandleRef.cs
- GregorianCalendarHelper.cs
- DescendantOverDescendantQuery.cs
- ListDataBindEventArgs.cs
- ISSmlParser.cs
- XmlSerializerNamespaces.cs
- HMAC.cs
- EventProvider.cs
- CodeMethodReturnStatement.cs
- XmlTextReaderImpl.cs
- ProcessModelSection.cs
- DesignerTransactionCloseEvent.cs
- SwitchElementsCollection.cs
- _TransmitFileOverlappedAsyncResult.cs
- SrgsRulesCollection.cs
- ConnectionPoolManager.cs
- ProfileSettings.cs
- OracleSqlParser.cs
- safex509handles.cs
- AliasGenerator.cs
- EventProvider.cs
- PrintingPermissionAttribute.cs
- KeyNotFoundException.cs
- BindToObject.cs
- Sorting.cs
- ViewStateException.cs
- SqlCommandSet.cs
- SymmetricSecurityBindingElement.cs
- HTTP_SERVICE_CONFIG_URLACL_PARAM.cs
- BaseTemplatedMobileComponentEditor.cs
- RtType.cs
- Attributes.cs
- ViewLoader.cs
- RemoteWebConfigurationHostStream.cs
- VectorCollection.cs
- XmlNode.cs
- AspNetSynchronizationContext.cs
- DataSourceBooleanViewSchemaConverter.cs
- X500Name.cs
- PenContext.cs
- CfgArc.cs
- _Connection.cs
- FileNotFoundException.cs
- SiteOfOriginPart.cs
- XmlSerializerAssemblyAttribute.cs
- WebServiceMethodData.cs
- InstanceNameConverter.cs
- HitTestParameters.cs
- RegisteredScript.cs
- cookie.cs
- FeatureSupport.cs
- KeyValuePairs.cs
- StylusEditingBehavior.cs
- nulltextcontainer.cs
- FusionWrap.cs
- HtmlInputText.cs
- CategoriesDocumentFormatter.cs
- DesignerRegionCollection.cs
- MessageSecurityException.cs
- SerializationSectionGroup.cs
- InvokeWebService.cs
- Polygon.cs
- CorrelationService.cs
- ControlPersister.cs
- ManagementInstaller.cs
- ForeignConstraint.cs
- AsymmetricSignatureDeformatter.cs
- TableCellCollection.cs
- QilInvokeEarlyBound.cs
- DbReferenceCollection.cs
- Codec.cs