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
- ListParagraph.cs
- ListViewDeleteEventArgs.cs
- StylusButtonCollection.cs
- Operand.cs
- KeyPressEvent.cs
- HtmlInputControl.cs
- ModelItemKeyValuePair.cs
- HandlerMappingMemo.cs
- GridErrorDlg.cs
- SubqueryRules.cs
- Binding.cs
- COM2IProvidePropertyBuilderHandler.cs
- WebPartTransformerAttribute.cs
- CodeDelegateInvokeExpression.cs
- TemplateControlParser.cs
- RadioButtonList.cs
- KeyEventArgs.cs
- DocumentReference.cs
- WindowsPen.cs
- ServiceNotStartedException.cs
- XPathNodeInfoAtom.cs
- OleDbDataReader.cs
- LoginUtil.cs
- NumberSubstitution.cs
- RegexBoyerMoore.cs
- UnknownBitmapEncoder.cs
- BitmapCodecInfoInternal.cs
- ObjectAssociationEndMapping.cs
- FixedTextSelectionProcessor.cs
- DirectionalLight.cs
- TextEffect.cs
- ExpressionReplacer.cs
- RangeBase.cs
- DataGridViewTopRowAccessibleObject.cs
- WaitForChangedResult.cs
- SecurityListenerSettingsLifetimeManager.cs
- PeerSecurityManager.cs
- DateTimeOffsetConverter.cs
- Crc32.cs
- HMACSHA512.cs
- LinqDataSourceView.cs
- EventTask.cs
- PipeStream.cs
- FillErrorEventArgs.cs
- PathSegmentCollection.cs
- CodeSnippetCompileUnit.cs
- DynamicMethod.cs
- CompiledIdentityConstraint.cs
- HwndStylusInputProvider.cs
- HttpCookieCollection.cs
- SeparatorAutomationPeer.cs
- Automation.cs
- Grant.cs
- PropertySourceInfo.cs
- ToolTipService.cs
- ComboBoxAutomationPeer.cs
- UidManager.cs
- _IPv6Address.cs
- StringFreezingAttribute.cs
- TransactionInterop.cs
- invalidudtexception.cs
- SecurityRuntime.cs
- SafeTimerHandle.cs
- xml.cs
- WebPartExportVerb.cs
- Page.cs
- RawContentTypeMapper.cs
- Int32Converter.cs
- TextDecoration.cs
- HttpWebResponse.cs
- xsdvalidator.cs
- ThrowHelper.cs
- ClientScriptManager.cs
- ZipIOExtraFieldPaddingElement.cs
- TemplateControlParser.cs
- TransformCollection.cs
- StandardBindingElementCollection.cs
- NameGenerator.cs
- WebPartVerbCollection.cs
- DataMemberConverter.cs
- RowBinding.cs
- BatchServiceHost.cs
- ThemeableAttribute.cs
- HttpPostProtocolReflector.cs
- EdmProperty.cs
- DrawListViewItemEventArgs.cs
- QilLiteral.cs
- log.cs
- ExtentKey.cs
- SystemResourceHost.cs
- ThicknessKeyFrameCollection.cs
- CounterSampleCalculator.cs
- CharConverter.cs
- SamlAttributeStatement.cs
- TrustManagerPromptUI.cs
- COAUTHINFO.cs
- EastAsianLunisolarCalendar.cs
- WebPartHelpVerb.cs
- StaticFileHandler.cs
- HttpInputStream.cs