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
- SessionStateItemCollection.cs
- templategroup.cs
- SafeWaitHandle.cs
- XmlValidatingReader.cs
- KeyboardDevice.cs
- AsyncPostBackErrorEventArgs.cs
- CultureInfo.cs
- ParsedAttributeCollection.cs
- DataGridLinkButton.cs
- Trace.cs
- FlowNode.cs
- ZipIOExtraField.cs
- DataSetMappper.cs
- AnimationTimeline.cs
- SQLMoneyStorage.cs
- WebPart.cs
- baseaxisquery.cs
- SafeProcessHandle.cs
- RectangleGeometry.cs
- FixedPosition.cs
- AgileSafeNativeMemoryHandle.cs
- ConfigXmlComment.cs
- TreeNodeConverter.cs
- TabPanel.cs
- EmptyControlCollection.cs
- SizeLimitedCache.cs
- GlyphRunDrawing.cs
- DataContractSet.cs
- CryptoKeySecurity.cs
- MinimizableAttributeTypeConverter.cs
- AsymmetricSignatureDeformatter.cs
- NamedPipeProcessProtocolHandler.cs
- LinkedResource.cs
- MessageEncoderFactory.cs
- IPEndPointCollection.cs
- ViewGenResults.cs
- FocusWithinProperty.cs
- MediaElement.cs
- MetabaseSettingsIis7.cs
- OracleDateTime.cs
- ItemsChangedEventArgs.cs
- ItemContainerGenerator.cs
- CodeGenerationManager.cs
- SystemFonts.cs
- DataTable.cs
- WithStatement.cs
- DesignerSerializationVisibilityAttribute.cs
- RSAPKCS1SignatureFormatter.cs
- BindingExpressionUncommonField.cs
- LineBreakRecord.cs
- GrowingArray.cs
- MetadataSource.cs
- ProcessInputEventArgs.cs
- HtmlInputRadioButton.cs
- ScriptManager.cs
- HostingPreferredMapPath.cs
- FieldAccessException.cs
- AutoResetEvent.cs
- DockPanel.cs
- ZipFileInfoCollection.cs
- XomlCompiler.cs
- FilteredXmlReader.cs
- ItemType.cs
- ResXDataNode.cs
- JavaScriptSerializer.cs
- PersonalizationProvider.cs
- AmbiguousMatchException.cs
- VBCodeProvider.cs
- CompositeActivityTypeDescriptorProvider.cs
- AssemblyName.cs
- SoapAttributeAttribute.cs
- NTAccount.cs
- DetailsViewPageEventArgs.cs
- PackageRelationshipCollection.cs
- CfgParser.cs
- BindingGroup.cs
- MultiBindingExpression.cs
- HwndAppCommandInputProvider.cs
- ReceiveParametersContent.cs
- RightsManagementEncryptedStream.cs
- ApplyTemplatesAction.cs
- ProcessModule.cs
- WebResourceUtil.cs
- EntityProviderFactory.cs
- ProfileService.cs
- TextServicesProperty.cs
- TreeWalker.cs
- SwitchElementsCollection.cs
- SrgsRuleRef.cs
- MappingException.cs
- DataKeyCollection.cs
- XmlUrlResolver.cs
- MimeObjectFactory.cs
- Span.cs
- ObjectRef.cs
- Soap.cs
- relpropertyhelper.cs
- Nodes.cs
- ProtocolsConfiguration.cs
- SpellerError.cs