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
- RelationalExpressions.cs
- QilFactory.cs
- TextEffect.cs
- smtppermission.cs
- DataGridPagerStyle.cs
- ContainerControlDesigner.cs
- EntityContainerAssociationSetEnd.cs
- Comparer.cs
- X509Extension.cs
- Mapping.cs
- FontStyleConverter.cs
- OutOfMemoryException.cs
- OleDbErrorCollection.cs
- InternalConfigConfigurationFactory.cs
- DesignerRegionMouseEventArgs.cs
- CodeMemberMethod.cs
- ToolStripGripRenderEventArgs.cs
- ConnectionStringSettings.cs
- TcpHostedTransportConfiguration.cs
- AvTrace.cs
- DateTimeOffsetAdapter.cs
- TableHeaderCell.cs
- DesignerVerbToolStripMenuItem.cs
- HttpHandlerAction.cs
- ComponentSerializationService.cs
- MachineKeySection.cs
- Intellisense.cs
- ValidationResult.cs
- ToolStripSeparatorRenderEventArgs.cs
- ListViewTableCell.cs
- SmtpAuthenticationManager.cs
- SecureUICommand.cs
- CroppedBitmap.cs
- MultipleCopiesCollection.cs
- Image.cs
- WebConfigurationHost.cs
- EmptyQuery.cs
- SerializationSectionGroup.cs
- CanonicalXml.cs
- ArrayTypeMismatchException.cs
- AccessViolationException.cs
- BooleanFunctions.cs
- BidPrivateBase.cs
- EdmFunctions.cs
- CodeGeneratorOptions.cs
- Utils.cs
- BatchWriter.cs
- FileBasedResourceGroveler.cs
- ExpressionValueEditor.cs
- ClientTargetCollection.cs
- SqlCachedBuffer.cs
- PointLightBase.cs
- HttpListenerPrefixCollection.cs
- COM2ColorConverter.cs
- FtpRequestCacheValidator.cs
- MobileListItemCollection.cs
- ContentPlaceHolder.cs
- PassportAuthenticationEventArgs.cs
- HighlightComponent.cs
- SecondaryIndexList.cs
- LineVisual.cs
- Win32PrintDialog.cs
- SqlError.cs
- XmlEventCache.cs
- ellipse.cs
- counter.cs
- SiteMembershipCondition.cs
- LoopExpression.cs
- SecondaryIndex.cs
- MouseGestureValueSerializer.cs
- ObjectAssociationEndMapping.cs
- CompiledRegexRunner.cs
- ThumbButtonInfoCollection.cs
- PresentationAppDomainManager.cs
- CharKeyFrameCollection.cs
- FileIOPermission.cs
- DbUpdateCommandTree.cs
- ConvertersCollection.cs
- Helpers.cs
- PixelShader.cs
- TagMapInfo.cs
- Mappings.cs
- ComplexTypeEmitter.cs
- SQLConvert.cs
- XsltLibrary.cs
- Rijndael.cs
- RecognitionResult.cs
- HMACSHA1.cs
- Pens.cs
- SqlXml.cs
- _TimerThread.cs
- WebPartCatalogCloseVerb.cs
- XmlSignatureProperties.cs
- UnmanagedMarshal.cs
- TextRangeEditTables.cs
- DynamicQueryableWrapper.cs
- ParameterCollection.cs
- PartBasedPackageProperties.cs
- ProtocolViolationException.cs
- CollectionChangeEventArgs.cs