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
- CounterCreationDataCollection.cs
- ComboBox.cs
- PropertyGroupDescription.cs
- DataGridViewSelectedRowCollection.cs
- EncodingDataItem.cs
- BitmapFrameDecode.cs
- InfoCardArgumentException.cs
- TextReader.cs
- OrderedDictionary.cs
- XmlAttributeCollection.cs
- CatalogPartCollection.cs
- ProfileProvider.cs
- MediaContextNotificationWindow.cs
- FormsAuthentication.cs
- CqlWriter.cs
- Token.cs
- StringCollection.cs
- ServiceDescriptionSerializer.cs
- GridView.cs
- CompressedStack.cs
- Propagator.cs
- RedBlackList.cs
- StrokeDescriptor.cs
- DataGridHeadersVisibilityToVisibilityConverter.cs
- Console.cs
- SrgsText.cs
- ListViewInsertEventArgs.cs
- VectorAnimationUsingKeyFrames.cs
- Console.cs
- ParseChildrenAsPropertiesAttribute.cs
- StoreItemCollection.Loader.cs
- PasswordTextNavigator.cs
- documentsequencetextpointer.cs
- UnSafeCharBuffer.cs
- MimeParameterWriter.cs
- OdbcParameterCollection.cs
- sqlnorm.cs
- PeerCollaborationPermission.cs
- DataListCommandEventArgs.cs
- SectionXmlInfo.cs
- TimersDescriptionAttribute.cs
- Color.cs
- ExtractorMetadata.cs
- SizeAnimationBase.cs
- XamlValidatingReader.cs
- SqlMetaData.cs
- SqlSupersetValidator.cs
- BufferModesCollection.cs
- CardSpaceSelector.cs
- TextReader.cs
- CodeAttributeArgument.cs
- OracleInternalConnection.cs
- SchemaImporterExtensionElement.cs
- HtmlTableCellCollection.cs
- SrgsSemanticInterpretationTag.cs
- DiscoveryEndpoint.cs
- MemoryMappedView.cs
- MenuItemBinding.cs
- DesignerHost.cs
- ContextProperty.cs
- RectKeyFrameCollection.cs
- DispatchWrapper.cs
- DtrList.cs
- BitmapScalingModeValidation.cs
- TerminatorSinks.cs
- CommandSet.cs
- NaturalLanguageHyphenator.cs
- RegexFCD.cs
- GPRECT.cs
- ReachVisualSerializer.cs
- ObjectResult.cs
- TextViewBase.cs
- TranslateTransform3D.cs
- XmlSortKey.cs
- VisualStyleInformation.cs
- AsymmetricAlgorithm.cs
- VisualBrush.cs
- XmlSerializerVersionAttribute.cs
- SiteMapProvider.cs
- COM2TypeInfoProcessor.cs
- WebPageTraceListener.cs
- ContextInformation.cs
- BuilderPropertyEntry.cs
- WebPartTracker.cs
- GeometryCombineModeValidation.cs
- EventPrivateKey.cs
- Guid.cs
- ActivityDesigner.cs
- AppSettingsExpressionBuilder.cs
- CultureSpecificStringDictionary.cs
- Overlapped.cs
- QilParameter.cs
- JpegBitmapDecoder.cs
- PrePrepareMethodAttribute.cs
- Run.cs
- XamlToRtfWriter.cs
- WSSecurityPolicy12.cs
- InputBuffer.cs
- XmlSchemas.cs
- FormClosedEvent.cs