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
- DataBinder.cs
- PathFigureCollectionValueSerializer.cs
- ListenerAdapter.cs
- RpcResponse.cs
- UnaryNode.cs
- Compress.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- CodeVariableReferenceExpression.cs
- Vector.cs
- InputScopeManager.cs
- SHA384Cng.cs
- QueryConverter.cs
- XmlReaderSettings.cs
- XmlProcessingInstruction.cs
- HitTestWithPointDrawingContextWalker.cs
- XPathArrayIterator.cs
- XmlSchemaSimpleContentRestriction.cs
- OverrideMode.cs
- ProxyElement.cs
- NameTable.cs
- UiaCoreProviderApi.cs
- CodeComment.cs
- codemethodreferenceexpression.cs
- SafeNativeMethods.cs
- SecurityTokenReferenceStyle.cs
- SystemIPv4InterfaceProperties.cs
- DependencySource.cs
- FormViewRow.cs
- TextContainerChangedEventArgs.cs
- DesignerGenericWebPart.cs
- Symbol.cs
- XmlFormatMapping.cs
- FormatterConverter.cs
- SymbolDocumentGenerator.cs
- COM2Enum.cs
- ResourceSetExpression.cs
- ConfigurationCollectionAttribute.cs
- AppDomain.cs
- IndexerNameAttribute.cs
- SystemIcons.cs
- DataGridViewCellCancelEventArgs.cs
- TreeNodeEventArgs.cs
- WindowsFormsLinkLabel.cs
- TableLayoutStyle.cs
- AsymmetricKeyExchangeFormatter.cs
- Activator.cs
- TextAdaptor.cs
- SiteMapNodeCollection.cs
- Themes.cs
- CopyEncoder.cs
- RectKeyFrameCollection.cs
- WebResourceUtil.cs
- PKCS1MaskGenerationMethod.cs
- CodeTypeReferenceExpression.cs
- XPathBuilder.cs
- SafeCoTaskMem.cs
- PropertyGridCommands.cs
- BufferModeSettings.cs
- XmlSchemaInclude.cs
- CircleHotSpot.cs
- RelatedCurrencyManager.cs
- ToolZone.cs
- XmlSignatureProperties.cs
- NamedPipeProcessProtocolHandler.cs
- FilePrompt.cs
- SerializationFieldInfo.cs
- SrgsElementList.cs
- Compress.cs
- SimpleWebHandlerParser.cs
- IPPacketInformation.cs
- WebBrowser.cs
- MsmqProcessProtocolHandler.cs
- ActivityExecutionContextCollection.cs
- SamlEvidence.cs
- CalendarDay.cs
- DataMisalignedException.cs
- HyperLinkField.cs
- TabControl.cs
- PackageRelationshipCollection.cs
- KeyGesture.cs
- BezierSegment.cs
- CallbackHandler.cs
- TableColumn.cs
- Metafile.cs
- TextSerializer.cs
- PropertyMapper.cs
- ReverseQueryOperator.cs
- GridViewCellAutomationPeer.cs
- StylusButtonEventArgs.cs
- UrlPath.cs
- SubtreeProcessor.cs
- PassportAuthentication.cs
- DataColumnMappingCollection.cs
- FixUpCollection.cs
- ObjectQuery_EntitySqlExtensions.cs
- streamingZipPartStream.cs
- BitmapMetadata.cs
- FunctionDescription.cs
- IndependentlyAnimatedPropertyMetadata.cs
- Mapping.cs