Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Configuration / Microsoft / Win32 / SafeNativeMemoryHandle.cs / 1 / SafeNativeMemoryHandle.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace Microsoft.Win32 { using System.Runtime.InteropServices; using System; using System.Security.Permissions; using Microsoft.Win32.SafeHandles; using System.Configuration; // Safehandle for memory handles [System.Security.SuppressUnmanagedCodeSecurityAttribute()] internal sealed class SafeNativeMemoryHandle : SafeHandleZeroOrMinusOneIsInvalid { private bool _useLocalFree = false; [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] internal SafeNativeMemoryHandle() : this(false) { } internal SafeNativeMemoryHandle(bool useLocalFree) : base(true) { _useLocalFree = useLocalFree; } [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] internal SafeNativeMemoryHandle(IntPtr handle, bool ownsHandle) : base(ownsHandle) { SetHandle(handle); } internal void SetDataHandle(IntPtr handle) { SetHandle(handle); } override protected bool ReleaseHandle() { if (handle != IntPtr.Zero) { if (_useLocalFree == true) UnsafeNativeMethods.LocalFree(handle); else Marshal.FreeHGlobal(handle); handle = IntPtr.Zero; return true; } return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace Microsoft.Win32 { using System.Runtime.InteropServices; using System; using System.Security.Permissions; using Microsoft.Win32.SafeHandles; using System.Configuration; // Safehandle for memory handles [System.Security.SuppressUnmanagedCodeSecurityAttribute()] internal sealed class SafeNativeMemoryHandle : SafeHandleZeroOrMinusOneIsInvalid { private bool _useLocalFree = false; [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] internal SafeNativeMemoryHandle() : this(false) { } internal SafeNativeMemoryHandle(bool useLocalFree) : base(true) { _useLocalFree = useLocalFree; } [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] internal SafeNativeMemoryHandle(IntPtr handle, bool ownsHandle) : base(ownsHandle) { SetHandle(handle); } internal void SetDataHandle(IntPtr handle) { SetHandle(handle); } override protected bool ReleaseHandle() { if (handle != IntPtr.Zero) { if (_useLocalFree == true) UnsafeNativeMethods.LocalFree(handle); else Marshal.FreeHGlobal(handle); handle = IntPtr.Zero; return true; } return false; } } } // 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
- ObjectStateManager.cs
- DocumentViewerBase.cs
- TypedReference.cs
- DataTableNameHandler.cs
- UpdateCompiler.cs
- FixedSOMGroup.cs
- TemplateKeyConverter.cs
- BrushConverter.cs
- AuthenticationService.cs
- AuthenticationSection.cs
- XmlWriterTraceListener.cs
- ProgressBar.cs
- Monitor.cs
- _LocalDataStore.cs
- ConvertEvent.cs
- ChangeToolStripParentVerb.cs
- SQLInt16Storage.cs
- InvalidFilterCriteriaException.cs
- ScrollPatternIdentifiers.cs
- AnnotationResourceChangedEventArgs.cs
- SafeFindHandle.cs
- SecurityException.cs
- CustomAttributeBuilder.cs
- TreeNodeClickEventArgs.cs
- SecurityCriticalDataForSet.cs
- InnerItemCollectionView.cs
- WebPartHeaderCloseVerb.cs
- MethodExpr.cs
- ContentElementCollection.cs
- EventlogProvider.cs
- ServicePoint.cs
- QuaternionAnimation.cs
- DetailsViewCommandEventArgs.cs
- RenderDataDrawingContext.cs
- ZoneIdentityPermission.cs
- PromptEventArgs.cs
- Delegate.cs
- PhysicalOps.cs
- ToolStripCodeDomSerializer.cs
- PolyBezierSegment.cs
- BasePropertyDescriptor.cs
- Label.cs
- DeflateStream.cs
- XmlDocumentSurrogate.cs
- InitiatorSessionSymmetricTransportSecurityProtocol.cs
- wmiprovider.cs
- ClassImporter.cs
- DbDeleteCommandTree.cs
- FrameDimension.cs
- KnownBoxes.cs
- ArraySortHelper.cs
- ILGenerator.cs
- EntityDataSourceContainerNameItem.cs
- Size3D.cs
- JournalEntry.cs
- ISAPIApplicationHost.cs
- DataGridViewRowCollection.cs
- BuildProvidersCompiler.cs
- ValidationRuleCollection.cs
- OnOperation.cs
- SiteOfOriginContainer.cs
- PropertyMetadata.cs
- _SslSessionsCache.cs
- StructuralComparisons.cs
- DropShadowEffect.cs
- WorkflowMarkupSerializationManager.cs
- AttachedProperty.cs
- SystemResources.cs
- CLSCompliantAttribute.cs
- RadioButtonAutomationPeer.cs
- IteratorFilter.cs
- CodeCommentStatement.cs
- Nullable.cs
- InternalTypeHelper.cs
- ProviderCollection.cs
- MultiView.cs
- OledbConnectionStringbuilder.cs
- CompositeFontFamily.cs
- SqlBulkCopyColumnMappingCollection.cs
- AngleUtil.cs
- PreservationFileWriter.cs
- ThreadStateException.cs
- XmlAtomicValue.cs
- _SecureChannel.cs
- AbandonedMutexException.cs
- Empty.cs
- SqlNode.cs
- ToolStripDropDownItem.cs
- TextTreeInsertUndoUnit.cs
- PropertyPathConverter.cs
- DataPager.cs
- ImportCatalogPart.cs
- COM2Enum.cs
- GPRECTF.cs
- ListArgumentProvider.cs
- BitmapVisualManager.cs
- TextContainer.cs
- RequestTimeoutManager.cs
- SafeEventHandle.cs
- _IPv6Address.cs