Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- DynamicResourceExtensionConverter.cs
- FontSource.cs
- IgnorePropertiesAttribute.cs
- SelectionItemPattern.cs
- TreeNodeStyleCollectionEditor.cs
- BitmapEffectGeneralTransform.cs
- WindowsStatusBar.cs
- XmlName.cs
- ActivityLocationReferenceEnvironment.cs
- PrimaryKeyTypeConverter.cs
- BindingExpressionUncommonField.cs
- TableHeaderCell.cs
- ImageEditor.cs
- DataGridPagingPage.cs
- OdbcEnvironmentHandle.cs
- WebPartRestoreVerb.cs
- RadioButton.cs
- ColumnPropertiesGroup.cs
- serverconfig.cs
- TemplateAction.cs
- MetabaseSettingsIis7.cs
- HttpGetProtocolReflector.cs
- TraceHelpers.cs
- KeyTime.cs
- Empty.cs
- XmlSchemaFacet.cs
- AmbientLight.cs
- ImageList.cs
- KeyedHashAlgorithm.cs
- ClientOptions.cs
- OperationContractAttribute.cs
- StateRuntime.cs
- Registration.cs
- ListViewUpdatedEventArgs.cs
- TextRunTypographyProperties.cs
- ContextBase.cs
- DataConnectionHelper.cs
- TypeResolver.cs
- TransportSecurityProtocol.cs
- SortableBindingList.cs
- WebColorConverter.cs
- BitmapEffectInputConnector.cs
- DataConnectionHelper.cs
- XPathAncestorQuery.cs
- MarkupExtensionReturnTypeAttribute.cs
- SourceFilter.cs
- ListViewInsertEventArgs.cs
- ZipPackage.cs
- ZoomPercentageConverter.cs
- SortFieldComparer.cs
- StringDictionary.cs
- ContextQuery.cs
- ChildDocumentBlock.cs
- SoundPlayer.cs
- View.cs
- SourceFileInfo.cs
- CLSCompliantAttribute.cs
- WebPartZoneBase.cs
- _PooledStream.cs
- DoubleAnimationClockResource.cs
- QuarticEase.cs
- NameTable.cs
- DesignerEventService.cs
- MulticastDelegate.cs
- WindowsListBox.cs
- SQLByteStorage.cs
- DbgUtil.cs
- EntityStoreSchemaGenerator.cs
- VolatileEnlistmentMultiplexing.cs
- BinHexDecoder.cs
- ServiceBuildProvider.cs
- UnsafeNativeMethods.cs
- CatalogPart.cs
- BoolLiteral.cs
- ProtocolViolationException.cs
- ParseElement.cs
- ToolStripRenderer.cs
- D3DImage.cs
- ColorMatrix.cs
- Misc.cs
- AsnEncodedData.cs
- Bezier.cs
- SynchronizedInputPattern.cs
- ToolStripControlHost.cs
- _LocalDataStore.cs
- Tool.cs
- Activator.cs
- XmlSchemaValidator.cs
- BuildProvider.cs
- TextureBrush.cs
- PageThemeCodeDomTreeGenerator.cs
- PermissionToken.cs
- SupportsEventValidationAttribute.cs
- ScrollPattern.cs
- AutomationPeer.cs
- SpinWait.cs
- rsa.cs
- _FtpDataStream.cs
- Keyboard.cs
- ObjectStateEntry.cs