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
- NameTable.cs
- ToolBar.cs
- DataViewSettingCollection.cs
- TransferRequestHandler.cs
- DataGridSortCommandEventArgs.cs
- HttpStreamFormatter.cs
- SoapReflectionImporter.cs
- RegexCharClass.cs
- BaseConfigurationRecord.cs
- BitmapImage.cs
- DataKey.cs
- Vector3D.cs
- GridViewCellAutomationPeer.cs
- FormClosedEvent.cs
- SRef.cs
- VirtualPathUtility.cs
- SystemIcmpV4Statistics.cs
- WebBrowserContainer.cs
- QuaternionIndependentAnimationStorage.cs
- RectAnimation.cs
- MobileTextWriter.cs
- DataGridViewRow.cs
- ManagementNamedValueCollection.cs
- BamlBinaryReader.cs
- WsatConfiguration.cs
- MailHeaderInfo.cs
- DataGridViewColumnStateChangedEventArgs.cs
- MatrixTransform.cs
- XPathEmptyIterator.cs
- RegistrationServices.cs
- InstanceView.cs
- DataViewSettingCollection.cs
- AlphabetConverter.cs
- QuaternionAnimationBase.cs
- TextElementEnumerator.cs
- SoapHeaders.cs
- sqlmetadatafactory.cs
- DeviceSpecificDialogCachedState.cs
- TrackingServices.cs
- _DomainName.cs
- InternalSafeNativeMethods.cs
- ProfileManager.cs
- WindowHelperService.cs
- CurrentChangingEventManager.cs
- ManifestResourceInfo.cs
- BitmapEffectInputData.cs
- EdmToObjectNamespaceMap.cs
- GenerateScriptTypeAttribute.cs
- AutomationIdentifierGuids.cs
- CodeMemberMethod.cs
- XmlBinaryReader.cs
- RangeValuePattern.cs
- BaseProcessor.cs
- AppSettingsReader.cs
- ResXResourceWriter.cs
- DbFunctionCommandTree.cs
- CopyCodeAction.cs
- AuthenticationModulesSection.cs
- EventLog.cs
- DataComponentMethodGenerator.cs
- RunWorkerCompletedEventArgs.cs
- SByteStorage.cs
- ProfileSection.cs
- GraphicsContainer.cs
- odbcmetadatacollectionnames.cs
- TypeSystem.cs
- TextSelectionProcessor.cs
- ShaderRenderModeValidation.cs
- WindowsGraphics.cs
- IdnMapping.cs
- VersionPair.cs
- DbProviderServices.cs
- FixedNode.cs
- ThemeDictionaryExtension.cs
- ToolStripPanelRow.cs
- DeferredTextReference.cs
- XMLDiffLoader.cs
- RuntimeHandles.cs
- Attributes.cs
- MessageBox.cs
- Point3DCollectionValueSerializer.cs
- ReadWriteControlDesigner.cs
- Page.cs
- XmlValidatingReaderImpl.cs
- XmlSchemaSimpleContentRestriction.cs
- Parameter.cs
- MultiTargetingUtil.cs
- ExceptionHandler.cs
- CqlWriter.cs
- HttpValueCollection.cs
- HasCopySemanticsAttribute.cs
- EditorPartCollection.cs
- PointAnimationUsingPath.cs
- dataobject.cs
- ActivityIdHeader.cs
- NeutralResourcesLanguageAttribute.cs
- CategoryGridEntry.cs
- SqlException.cs
- Propagator.cs
- StylusShape.cs