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
- BuilderPropertyEntry.cs
- JsonFormatWriterGenerator.cs
- CompilerErrorCollection.cs
- Package.cs
- HMACRIPEMD160.cs
- Metadata.cs
- MissingSatelliteAssemblyException.cs
- VectorCollectionValueSerializer.cs
- ValidationErrorCollection.cs
- DBBindings.cs
- AsnEncodedData.cs
- DataGridColumnHeaderItemAutomationPeer.cs
- MetadataItem_Static.cs
- NativeMethods.cs
- XmlAtomErrorReader.cs
- DispatcherExceptionEventArgs.cs
- TypeLoadException.cs
- BrowserCapabilitiesCodeGenerator.cs
- FunctionCommandText.cs
- Dictionary.cs
- PackageRelationship.cs
- DesignTimeTemplateParser.cs
- DynamicMethod.cs
- LiteralControl.cs
- hebrewshape.cs
- VectorKeyFrameCollection.cs
- DPTypeDescriptorContext.cs
- ZipIOCentralDirectoryBlock.cs
- WebBrowserNavigatingEventHandler.cs
- XmlSchemaObjectCollection.cs
- MeasureData.cs
- processwaithandle.cs
- CollectionChangeEventArgs.cs
- ThemeDictionaryExtension.cs
- ControlDesigner.cs
- OdbcConnectionFactory.cs
- EntityRecordInfo.cs
- LessThanOrEqual.cs
- EntityDataSourceValidationException.cs
- SecurityToken.cs
- HtmlTableRow.cs
- AmbientLight.cs
- Connector.cs
- DataBoundLiteralControl.cs
- Wildcard.cs
- HtmlTitle.cs
- COM2Properties.cs
- ByteKeyFrameCollection.cs
- Adorner.cs
- DataGridCellsPanel.cs
- SinglePageViewer.cs
- XsdCachingReader.cs
- JournalEntryStack.cs
- NonBatchDirectoryCompiler.cs
- CharacterBufferReference.cs
- CatalogZoneBase.cs
- Polygon.cs
- CacheSection.cs
- SymDocumentType.cs
- ScrollableControlDesigner.cs
- PropertyGridDesigner.cs
- DesigntimeLicenseContextSerializer.cs
- XmlExceptionHelper.cs
- HttpProcessUtility.cs
- KoreanCalendar.cs
- FrameworkRichTextComposition.cs
- RegexReplacement.cs
- DoubleConverter.cs
- MultilineStringConverter.cs
- ConnectionStringsExpressionBuilder.cs
- DoubleLinkList.cs
- KerberosReceiverSecurityToken.cs
- CultureInfoConverter.cs
- DbConnectionHelper.cs
- ManagedIStream.cs
- DataListComponentEditor.cs
- ExpandSegment.cs
- DescendantQuery.cs
- PageAsyncTaskManager.cs
- DataGridViewRowEventArgs.cs
- BaseTypeViewSchema.cs
- XMLSchema.cs
- DateTimeConstantAttribute.cs
- Hash.cs
- ReflectTypeDescriptionProvider.cs
- TextTreePropertyUndoUnit.cs
- CodeTypeReferenceExpression.cs
- Queue.cs
- ServicePointManager.cs
- CompilerErrorCollection.cs
- TypeListConverter.cs
- DrawingDrawingContext.cs
- HtmlInputRadioButton.cs
- TreeChangeInfo.cs
- MDIWindowDialog.cs
- CorrelationTokenInvalidatedHandler.cs
- RetrieveVirtualItemEventArgs.cs
- CodeSnippetStatement.cs
- BasicExpressionVisitor.cs
- TimeSpanMinutesConverter.cs