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
- TextContainerChangedEventArgs.cs
- Pool.cs
- MultiByteCodec.cs
- SoapClientProtocol.cs
- ConfigXmlSignificantWhitespace.cs
- Nullable.cs
- DataGridViewImageColumn.cs
- DrawingContext.cs
- Odbc32.cs
- EnvelopedSignatureTransform.cs
- GeometryModel3D.cs
- WebPartsPersonalizationAuthorization.cs
- RecipientInfo.cs
- Rules.cs
- METAHEADER.cs
- SerializationFieldInfo.cs
- IdleTimeoutMonitor.cs
- ArrowControl.xaml.cs
- Animatable.cs
- SRDisplayNameAttribute.cs
- Rfc2898DeriveBytes.cs
- RawStylusInputReport.cs
- CodeVariableReferenceExpression.cs
- RelationalExpressions.cs
- BasicHttpBindingCollectionElement.cs
- BitSet.cs
- MemberProjectedSlot.cs
- EntityTypeBase.cs
- DataGridViewCellValidatingEventArgs.cs
- KeyboardEventArgs.cs
- WorkflowApplication.cs
- EnumerableWrapperWeakToStrong.cs
- PointIndependentAnimationStorage.cs
- IsolatedStorageFilePermission.cs
- BuildProviderCollection.cs
- FormViewModeEventArgs.cs
- GuidTagList.cs
- ScriptComponentDescriptor.cs
- AssociationProvider.cs
- DmlSqlGenerator.cs
- Stack.cs
- DataDocumentXPathNavigator.cs
- MenuItem.cs
- TagNameToTypeMapper.cs
- WindowInteractionStateTracker.cs
- RawAppCommandInputReport.cs
- RuntimeWrappedException.cs
- PresentationAppDomainManager.cs
- SurrogateDataContract.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- FixedDocument.cs
- ThicknessAnimation.cs
- OutputScope.cs
- TraceSection.cs
- HashCryptoHandle.cs
- BaseCodeDomTreeGenerator.cs
- ChildTable.cs
- storepermission.cs
- NavigationPropertyEmitter.cs
- ExpressionBuilder.cs
- contentDescriptor.cs
- _SslState.cs
- ManifestResourceInfo.cs
- FileAuthorizationModule.cs
- ServiceMemoryGates.cs
- ExtenderProvidedPropertyAttribute.cs
- XamlReaderHelper.cs
- figurelengthconverter.cs
- ImageProxy.cs
- TableAdapterManagerMethodGenerator.cs
- SqlReferenceCollection.cs
- WebRequestModuleElement.cs
- PackageRelationshipCollection.cs
- PreviewPageInfo.cs
- DebugView.cs
- SequentialWorkflowRootDesigner.cs
- FixedSOMPage.cs
- StringConverter.cs
- DefaultPrintController.cs
- TypeLibConverter.cs
- HttpClientCertificate.cs
- QueryReaderSettings.cs
- FontUnit.cs
- QilParameter.cs
- MethodCallTranslator.cs
- MessageEncoder.cs
- EntityExpressionVisitor.cs
- WeakReferenceEnumerator.cs
- ContentElementAutomationPeer.cs
- MimeFormatter.cs
- TypedServiceChannelBuilder.cs
- WindowsFormsHostPropertyMap.cs
- SecurityTokenValidationException.cs
- SQLCharsStorage.cs
- ConfigXmlAttribute.cs
- ElementHostAutomationPeer.cs
- ProviderException.cs
- Application.cs
- Compilation.cs
- Symbol.cs