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
- SubpageParagraph.cs
- DataPager.cs
- HitTestResult.cs
- InkCanvasInnerCanvas.cs
- ReadOnlyDataSourceView.cs
- StylusPlugInCollection.cs
- CriticalHandle.cs
- NameTable.cs
- XamlRtfConverter.cs
- GridSplitterAutomationPeer.cs
- _ProxyChain.cs
- Win32Native.cs
- SafeNativeMethodsMilCoreApi.cs
- DES.cs
- Itemizer.cs
- HandlerWithFactory.cs
- SelectionWordBreaker.cs
- IsolationInterop.cs
- XPathException.cs
- activationcontext.cs
- DivideByZeroException.cs
- SelectionUIService.cs
- LinqExpressionNormalizer.cs
- InputReportEventArgs.cs
- XmlSubtreeReader.cs
- LinqDataSourceUpdateEventArgs.cs
- ConnectivityStatus.cs
- EntitySqlQueryState.cs
- EntitySqlQueryCacheKey.cs
- Rule.cs
- QueryCacheManager.cs
- WebHttpEndpointElement.cs
- safelink.cs
- MarkupCompiler.cs
- AuthenticatingEventArgs.cs
- HtmlControlPersistable.cs
- WorkflowQueue.cs
- URLMembershipCondition.cs
- CodeTypeDeclaration.cs
- NaturalLanguageHyphenator.cs
- COM2ExtendedUITypeEditor.cs
- PanelDesigner.cs
- ToolStripScrollButton.cs
- COM2ComponentEditor.cs
- DesignBindingValueUIHandler.cs
- Geometry.cs
- WinFormsUtils.cs
- PublisherMembershipCondition.cs
- PopOutPanel.cs
- SourceItem.cs
- DataPagerCommandEventArgs.cs
- updateconfighost.cs
- SByteConverter.cs
- xml.cs
- UseLicense.cs
- XMLUtil.cs
- Vertex.cs
- XmlDataProvider.cs
- KeyValueConfigurationElement.cs
- ConfigurationCollectionAttribute.cs
- WhereaboutsReader.cs
- ScrollItemPattern.cs
- XmlWellformedWriter.cs
- NullRuntimeConfig.cs
- LogLogRecordEnumerator.cs
- ChangeTracker.cs
- QueueException.cs
- ThicknessConverter.cs
- PerformanceCounterPermissionAttribute.cs
- XmlMembersMapping.cs
- HandleCollector.cs
- SafeLocalMemHandle.cs
- MappingModelBuildProvider.cs
- VirtualPath.cs
- ForeignConstraint.cs
- OneToOneMappingSerializer.cs
- ApplicationFileParser.cs
- SQLByte.cs
- XmlHelper.cs
- URLMembershipCondition.cs
- TraceEventCache.cs
- MinimizableAttributeTypeConverter.cs
- IgnoreSectionHandler.cs
- DetailsViewPageEventArgs.cs
- ExpandableObjectConverter.cs
- DataGridViewAutoSizeModeEventArgs.cs
- CodeCompileUnit.cs
- ParameterElementCollection.cs
- UnsafeCollabNativeMethods.cs
- ConfigViewGenerator.cs
- WebPartVerbCollection.cs
- HybridObjectCache.cs
- OleServicesContext.cs
- VerticalAlignConverter.cs
- CaseInsensitiveOrdinalStringComparer.cs
- XmlSchemaComplexType.cs
- EncoderExceptionFallback.cs
- TextEffect.cs
- KeyedCollection.cs
- NavigationProperty.cs