Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- WorkflowDebuggerSteppingAttribute.cs
- FocusManager.cs
- Calendar.cs
- InfoCardCryptoHelper.cs
- TransactionOptions.cs
- HttpConfigurationContext.cs
- RtType.cs
- DesignerLoader.cs
- RIPEMD160Managed.cs
- ProcessHostConfigUtils.cs
- WebPartConnection.cs
- AuthenticationManager.cs
- BigInt.cs
- ArraySegment.cs
- Int16AnimationBase.cs
- FileUpload.cs
- SByte.cs
- GradientSpreadMethodValidation.cs
- Lease.cs
- SubMenuStyleCollection.cs
- ObjectListTitleAttribute.cs
- PageContentCollection.cs
- SortAction.cs
- XmlJsonReader.cs
- ConnectionStringsExpressionBuilder.cs
- xml.cs
- PageAsyncTaskManager.cs
- TreeNodeSelectionProcessor.cs
- DoubleLinkListEnumerator.cs
- Stack.cs
- TransformValueSerializer.cs
- PrintPreviewControl.cs
- WebPartConnectionsCloseVerb.cs
- AdRotator.cs
- RTLAwareMessageBox.cs
- TitleStyle.cs
- FixedLineResult.cs
- ApplicationServicesHostFactory.cs
- KeyValuePair.cs
- PolicyLevel.cs
- InputMethod.cs
- MetadataCache.cs
- Activity.cs
- XmlRootAttribute.cs
- ListComponentEditorPage.cs
- TagMapInfo.cs
- OutputCacheModule.cs
- DiffuseMaterial.cs
- StringAttributeCollection.cs
- DecoderReplacementFallback.cs
- DateTimeFormatInfo.cs
- DateTimeFormatInfo.cs
- CustomError.cs
- ClientUrlResolverWrapper.cs
- DataGridViewSelectedCellCollection.cs
- BaseResourcesBuildProvider.cs
- SqlLiftIndependentRowExpressions.cs
- XhtmlBasicCalendarAdapter.cs
- __Error.cs
- DataGridViewRowConverter.cs
- CurrentChangingEventManager.cs
- PropertyDescriptorCollection.cs
- ServiceEndpointElementCollection.cs
- EdmRelationshipRoleAttribute.cs
- TouchesOverProperty.cs
- TraceUtility.cs
- ImageButton.cs
- LinqDataSourceStatusEventArgs.cs
- Int32RectValueSerializer.cs
- DesignTimeSiteMapProvider.cs
- ExpressionReplacer.cs
- NameNode.cs
- WebConfigurationHostFileChange.cs
- DefaultMemberAttribute.cs
- DescendantQuery.cs
- ControlCachePolicy.cs
- ExceptionWrapper.cs
- MetafileHeaderWmf.cs
- SqlCommand.cs
- BooleanAnimationUsingKeyFrames.cs
- HighlightComponent.cs
- PointLight.cs
- ToolboxItemFilterAttribute.cs
- DataObjectPastingEventArgs.cs
- Utils.cs
- StateChangeEvent.cs
- SystemException.cs
- XamlStyleSerializer.cs
- StringKeyFrameCollection.cs
- RegexCapture.cs
- MatrixTransform.cs
- OdbcConnection.cs
- SqlRecordBuffer.cs
- MailAddressParser.cs
- DefaultWorkflowSchedulerService.cs
- TextWriterTraceListener.cs
- DefinitionUpdate.cs
- ProfileProvider.cs
- DataSetMappper.cs
- OdbcConnectionPoolProviderInfo.cs