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
- PropertyGrid.cs
- XmlSchemaSubstitutionGroup.cs
- BaseParser.cs
- ProvidersHelper.cs
- MailWriter.cs
- X509Utils.cs
- ProviderManager.cs
- RootAction.cs
- VisualCollection.cs
- ChangePasswordDesigner.cs
- XmlNode.cs
- DataGridViewCellStyle.cs
- EntityContainer.cs
- AssertFilter.cs
- CodeNamespace.cs
- SapiRecoInterop.cs
- controlskin.cs
- WindowsRichEdit.cs
- OracleException.cs
- TailCallAnalyzer.cs
- RepeatButtonAutomationPeer.cs
- SystemBrushes.cs
- SafeLibraryHandle.cs
- CalendarItem.cs
- SchemaNames.cs
- StateBag.cs
- NavigationWindowAutomationPeer.cs
- ColumnCollection.cs
- EntityCollection.cs
- GacUtil.cs
- HttpModuleCollection.cs
- SqlFlattener.cs
- PersonalizationProviderHelper.cs
- COM2PictureConverter.cs
- AbsoluteQuery.cs
- SQLBytesStorage.cs
- VBIdentifierDesigner.xaml.cs
- Polyline.cs
- DependencyProperty.cs
- RelationshipNavigation.cs
- AndMessageFilterTable.cs
- TargetParameterCountException.cs
- COM2FontConverter.cs
- SystemIcmpV6Statistics.cs
- SchemaAttDef.cs
- diagnosticsswitches.cs
- CollectionContainer.cs
- TextParagraph.cs
- WebRequestModuleElementCollection.cs
- DescendantOverDescendantQuery.cs
- TrueReadOnlyCollection.cs
- ConfigXmlComment.cs
- ScalarType.cs
- SecurityKeyUsage.cs
- DiffuseMaterial.cs
- OperationCanceledException.cs
- ListenerConnectionDemuxer.cs
- EUCJPEncoding.cs
- activationcontext.cs
- DataGridViewImageCell.cs
- DBConnection.cs
- MediaElementAutomationPeer.cs
- DataKeyPropertyAttribute.cs
- FlowPosition.cs
- entityreference_tresulttype.cs
- WizardStepBase.cs
- EntityParameter.cs
- EntitySetBaseCollection.cs
- Selector.cs
- Helpers.cs
- OleDbInfoMessageEvent.cs
- SafeLibraryHandle.cs
- ProbeMatchesCD1.cs
- ToolBar.cs
- SqlNotificationRequest.cs
- ToolStripItemTextRenderEventArgs.cs
- CodeParameterDeclarationExpressionCollection.cs
- CopyNamespacesAction.cs
- ApplicationInterop.cs
- FrameworkTextComposition.cs
- ListViewItemSelectionChangedEvent.cs
- DataListItemEventArgs.cs
- InvalidOperationException.cs
- DetailsViewUpdateEventArgs.cs
- RenderDataDrawingContext.cs
- COAUTHIDENTITY.cs
- CodeAccessPermission.cs
- WebServicesInteroperability.cs
- LockCookie.cs
- CallSiteBinder.cs
- DataSourceSelectArguments.cs
- MenuStrip.cs
- DBAsyncResult.cs
- SpellerStatusTable.cs
- EditorZone.cs
- PathSegmentCollection.cs
- PropertyDescriptorGridEntry.cs
- SafeHandles.cs
- SByteStorage.cs
- ProjectionQueryOptionExpression.cs