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
- ToolboxDataAttribute.cs
- Base64Stream.cs
- QuadraticBezierSegment.cs
- EventLogEntry.cs
- MessageDesigner.cs
- RelOps.cs
- XPathDocumentIterator.cs
- Filter.cs
- XmlSerializationReader.cs
- EncoderReplacementFallback.cs
- SqlResolver.cs
- XmlEncoding.cs
- PersonalizableTypeEntry.cs
- TimeIntervalCollection.cs
- MethodExpr.cs
- WorkflowNamespace.cs
- XhtmlBasicPanelAdapter.cs
- ErrorHandler.cs
- MaskInputRejectedEventArgs.cs
- BookmarkCallbackWrapper.cs
- HashHelper.cs
- Visual3DCollection.cs
- HuffModule.cs
- DataGridViewIntLinkedList.cs
- isolationinterop.cs
- InstallerTypeAttribute.cs
- XsdBuildProvider.cs
- SystemWebSectionGroup.cs
- ResXResourceSet.cs
- BinaryObjectReader.cs
- mediaeventshelper.cs
- HashHelper.cs
- TileBrush.cs
- HitTestWithGeometryDrawingContextWalker.cs
- MatchAllMessageFilter.cs
- FormsAuthenticationConfiguration.cs
- HashCodeCombiner.cs
- DataControlLinkButton.cs
- Wizard.cs
- BulletedListDesigner.cs
- XmlSchemaValidationException.cs
- CompiledXpathExpr.cs
- ListViewSortEventArgs.cs
- InputBinding.cs
- DataPagerCommandEventArgs.cs
- EntityDataSourceWrapper.cs
- SafeMILHandle.cs
- BinaryObjectWriter.cs
- ByteAnimation.cs
- ObsoleteAttribute.cs
- Viewport3DVisual.cs
- ListComponentEditorPage.cs
- DbConnectionClosed.cs
- DataGridViewDataConnection.cs
- XPathPatternParser.cs
- Label.cs
- ListViewSelectEventArgs.cs
- SetterBase.cs
- PointLightBase.cs
- UnknownExceptionActionHelper.cs
- XmlSchemaDatatype.cs
- WebBrowserDocumentCompletedEventHandler.cs
- DataGridViewButtonColumn.cs
- DbParameterCollectionHelper.cs
- FontDifferentiator.cs
- XmlSchemaDatatype.cs
- RawStylusSystemGestureInputReport.cs
- ImageMapEventArgs.cs
- CookielessHelper.cs
- ImageSourceValueSerializer.cs
- ConnectionStringEditor.cs
- InfiniteTimeSpanConverter.cs
- XmlWhitespace.cs
- ToolStripArrowRenderEventArgs.cs
- CodeAssignStatement.cs
- TableSectionStyle.cs
- WS2007FederationHttpBindingCollectionElement.cs
- xml.cs
- TranslateTransform.cs
- ApplicationGesture.cs
- Image.cs
- SchemaElement.cs
- SetStoryboardSpeedRatio.cs
- StylusCaptureWithinProperty.cs
- Cursor.cs
- ConversionValidationRule.cs
- WindowsGraphicsWrapper.cs
- CalendarDataBindingHandler.cs
- WorkflowDebuggerSteppingAttribute.cs
- AbandonedMutexException.cs
- hwndwrapper.cs
- WaitHandle.cs
- DSASignatureDeformatter.cs
- IFlowDocumentViewer.cs
- TextEncodedRawTextWriter.cs
- ContentWrapperAttribute.cs
- TransactionScope.cs
- ListViewItemEventArgs.cs
- KerberosReceiverSecurityToken.cs
- ProcessModule.cs