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
- WpfKnownType.cs
- ProxyHwnd.cs
- PnrpPeerResolver.cs
- XmlValidatingReaderImpl.cs
- DecoderReplacementFallback.cs
- AutoResetEvent.cs
- MatrixTransform.cs
- WrapperEqualityComparer.cs
- Fonts.cs
- ControlBuilderAttribute.cs
- StringAttributeCollection.cs
- HtmlInputPassword.cs
- UnionCqlBlock.cs
- HostingEnvironmentException.cs
- SchemaDeclBase.cs
- CompositeActivityDesigner.cs
- CounterCreationData.cs
- ProviderCommandInfoUtils.cs
- AutomationElementCollection.cs
- DisplayInformation.cs
- ScrollBar.cs
- XmlDataDocument.cs
- AutomationAttributeInfo.cs
- PreviewPrintController.cs
- UriExt.cs
- MemberDomainMap.cs
- TextBoxBase.cs
- SqlCommandBuilder.cs
- OdbcDataReader.cs
- PropertyStore.cs
- LocatorPartList.cs
- PersonalizationStateQuery.cs
- EventLog.cs
- StringComparer.cs
- XmlDocument.cs
- SoapAttributeAttribute.cs
- Solver.cs
- QuaternionConverter.cs
- WindowsTab.cs
- DebugInfo.cs
- WindowsStartMenu.cs
- TcpStreams.cs
- DefaultDialogButtons.cs
- GridViewPageEventArgs.cs
- Stylesheet.cs
- TagPrefixAttribute.cs
- BlurBitmapEffect.cs
- DataView.cs
- CodeExporter.cs
- RuleSetReference.cs
- SvcFileManager.cs
- BasePattern.cs
- XmlSchemaImport.cs
- safePerfProviderHandle.cs
- SoapExtensionReflector.cs
- BamlLocalizableResource.cs
- DataSourceSelectArguments.cs
- ApplicationTrust.cs
- TextEditorCopyPaste.cs
- WebServiceErrorEvent.cs
- XmlDigitalSignatureProcessor.cs
- RegexRunnerFactory.cs
- StringArrayConverter.cs
- TreeSet.cs
- ClientSettings.cs
- SafePipeHandle.cs
- ToolboxItemCollection.cs
- DynamicILGenerator.cs
- FlowDocumentFormatter.cs
- WebPartEditVerb.cs
- SqlUdtInfo.cs
- AccessViolationException.cs
- AspNetHostingPermission.cs
- FormViewInsertEventArgs.cs
- InputScopeAttribute.cs
- _ListenerAsyncResult.cs
- ClonableStack.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- WindowsStartMenu.cs
- ReferentialConstraintRoleElement.cs
- CssStyleCollection.cs
- TableColumnCollection.cs
- XsdValidatingReader.cs
- ValidationEventArgs.cs
- safex509handles.cs
- ToolStripOverflowButton.cs
- WindowsListViewItemCheckBox.cs
- ComplexPropertyEntry.cs
- ListenerElementsCollection.cs
- XamlWrapperReaders.cs
- AmbiguousMatchException.cs
- FilteredReadOnlyMetadataCollection.cs
- XPathSingletonIterator.cs
- RenamedEventArgs.cs
- HttpFileCollection.cs
- UserPersonalizationStateInfo.cs
- SafeFileMapViewHandle.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- XmlCharacterData.cs
- MissingManifestResourceException.cs