Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / Microsoft / Win32 / SafeNativeMemoryHandle.cs / 1305376 / 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
- ViewBox.cs
- RelationshipEndCollection.cs
- MobileCategoryAttribute.cs
- DateTimeOffset.cs
- ValidatorCollection.cs
- dbenumerator.cs
- ConvertBinder.cs
- coordinatorscratchpad.cs
- DrawingVisualDrawingContext.cs
- SqlInfoMessageEvent.cs
- MsmqMessage.cs
- LocationSectionRecord.cs
- AnnotationResourceCollection.cs
- EntityModelSchemaGenerator.cs
- SequenceDesigner.cs
- RequiredFieldValidator.cs
- EpmContentDeSerializerBase.cs
- DataTableClearEvent.cs
- ServiceModelTimeSpanValidator.cs
- Accessors.cs
- StackSpiller.cs
- AdornerHitTestResult.cs
- DynamicPropertyReader.cs
- NavigationPropertyEmitter.cs
- TypeConvertions.cs
- DrawingContextDrawingContextWalker.cs
- HtmlTableCell.cs
- OperationCanceledException.cs
- ValueUnavailableException.cs
- XmlSerializationGeneratedCode.cs
- EntityDataSourceChangingEventArgs.cs
- WindowsEditBoxRange.cs
- Point.cs
- ChildTable.cs
- graph.cs
- FixedSOMTableRow.cs
- DesignTimeParseData.cs
- FileDocument.cs
- InstalledVoice.cs
- XpsDocument.cs
- IIS7UserPrincipal.cs
- BuildResult.cs
- DataGridAutoFormat.cs
- TemplateInstanceAttribute.cs
- XsdDataContractImporter.cs
- StdValidatorsAndConverters.cs
- XmlNode.cs
- PrtCap_Public_Simple.cs
- DataGridRow.cs
- XmlObjectSerializerWriteContext.cs
- listitem.cs
- StorageBasedPackageProperties.cs
- KoreanCalendar.cs
- AddInServer.cs
- TextElementAutomationPeer.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- BezierSegment.cs
- RecordsAffectedEventArgs.cs
- IDReferencePropertyAttribute.cs
- WindowsGraphics2.cs
- IERequestCache.cs
- TypedDatasetGenerator.cs
- MouseGesture.cs
- PropertyGridEditorPart.cs
- XmlQueryRuntime.cs
- DoubleLink.cs
- InvalidDataException.cs
- SystemIPGlobalStatistics.cs
- ServiceInfo.cs
- Variable.cs
- ToolBarDesigner.cs
- RichTextBox.cs
- MailWebEventProvider.cs
- RuntimeIdentifierPropertyAttribute.cs
- ZoomPercentageConverter.cs
- StoragePropertyMapping.cs
- PropertyDescriptorCollection.cs
- FloaterBaseParaClient.cs
- InputDevice.cs
- panel.cs
- SqlPersistenceWorkflowInstanceDescription.cs
- QueryableFilterRepeater.cs
- AccessorTable.cs
- ConfigViewGenerator.cs
- DynamicControl.cs
- SafePointer.cs
- _UriSyntax.cs
- SystemFonts.cs
- CompilerErrorCollection.cs
- ToolboxItem.cs
- SqlIdentifier.cs
- RegionInfo.cs
- MediaCommands.cs
- _NegotiateClient.cs
- PngBitmapEncoder.cs
- Enlistment.cs
- FormsIdentity.cs
- ExeConfigurationFileMap.cs
- AppDomainManager.cs
- ImmutableObjectAttribute.cs