Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- RadioButton.cs
- ListControl.cs
- MessageBox.cs
- PeerNameResolver.cs
- PrintDialog.cs
- SchemaContext.cs
- SecurityCriticalDataForSet.cs
- RC2CryptoServiceProvider.cs
- IndicCharClassifier.cs
- TableLayoutStyleCollection.cs
- StylusPlugin.cs
- CommentEmitter.cs
- ProxyAttribute.cs
- TableParaClient.cs
- CuspData.cs
- DelegateHelpers.Generated.cs
- DataViewSetting.cs
- BamlRecordReader.cs
- EntityUtil.cs
- RepeatBehaviorConverter.cs
- followingsibling.cs
- PresentationSource.cs
- SendKeys.cs
- FormViewPageEventArgs.cs
- OdbcHandle.cs
- EncryptedKey.cs
- QueryStringParameter.cs
- ExpandSegment.cs
- LoginView.cs
- JsonReaderWriterFactory.cs
- RadioButtonPopupAdapter.cs
- ExpressionVisitor.cs
- DataGridCheckBoxColumn.cs
- TagPrefixCollection.cs
- BufferedStream.cs
- SchemaCollectionPreprocessor.cs
- DoubleConverter.cs
- DetailsViewRow.cs
- BuildProviderAppliesToAttribute.cs
- UnsafeNativeMethods.cs
- Point4D.cs
- FormattedTextSymbols.cs
- XmlSchemaSet.cs
- XPathNavigatorReader.cs
- ListBox.cs
- CodeEventReferenceExpression.cs
- StateItem.cs
- DataGridViewComboBoxEditingControl.cs
- XmlHelper.cs
- SnapLine.cs
- AttributeSetAction.cs
- RadialGradientBrush.cs
- EncryptedKey.cs
- RewritingProcessor.cs
- EllipticalNodeOperations.cs
- Component.cs
- FileFormatException.cs
- FileRecordSequenceHelper.cs
- PlaceHolder.cs
- ShutDownListener.cs
- Operand.cs
- SqlFunctions.cs
- SerializeAbsoluteContext.cs
- XmlSchemaAny.cs
- RtfToXamlLexer.cs
- ConstructorNeedsTagAttribute.cs
- XmlWhitespace.cs
- Processor.cs
- Subtree.cs
- StatusBarItem.cs
- XmlCountingReader.cs
- columnmapkeybuilder.cs
- DataGridColumnEventArgs.cs
- Int16AnimationUsingKeyFrames.cs
- Column.cs
- StructuredTypeEmitter.cs
- XmlSchemaProviderAttribute.cs
- AccessControlList.cs
- WhitespaceRuleLookup.cs
- PageAdapter.cs
- Completion.cs
- ListenerBinder.cs
- QuarticEase.cs
- ExpressionBuilder.cs
- InputLangChangeEvent.cs
- Pair.cs
- SHA1Managed.cs
- HttpContext.cs
- DataGridViewAdvancedBorderStyle.cs
- SessionPageStateSection.cs
- AppDomainResourcePerfCounters.cs
- Transform3DGroup.cs
- HttpApplication.cs
- ConditionalAttribute.cs
- ValidatedControlConverter.cs
- EmptyQuery.cs
- JapaneseLunisolarCalendar.cs
- ConfigXmlWhitespace.cs
- Line.cs
- HttpWebRequestElement.cs