Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / Microsoft / Win32 / SafeNativeMemoryHandle.cs / 1305376 / 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
- HttpServerProtocol.cs
- SystemIPGlobalProperties.cs
- FloaterBaseParaClient.cs
- RadioButton.cs
- CellQuery.cs
- RepeatButton.cs
- DataServiceQueryOfT.cs
- MatrixCamera.cs
- FixedSOMGroup.cs
- EditorAttribute.cs
- InstanceBehavior.cs
- KeyboardInputProviderAcquireFocusEventArgs.cs
- DnsPermission.cs
- VirtualPathProvider.cs
- SortExpressionBuilder.cs
- EngineSite.cs
- SystemIPGlobalProperties.cs
- DataSvcMapFileSerializer.cs
- XmlSchemaSubstitutionGroup.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- WsiProfilesElement.cs
- FileSecurity.cs
- EventProviderWriter.cs
- ExpressionVisitor.cs
- HttpClientCertificate.cs
- MenuAdapter.cs
- CommentGlyph.cs
- RadioButtonList.cs
- NavigationPropertySingletonExpression.cs
- PickDesigner.xaml.cs
- COM2ExtendedTypeConverter.cs
- WhitespaceReader.cs
- NamespaceExpr.cs
- CaseInsensitiveOrdinalStringComparer.cs
- CapabilitiesPattern.cs
- ApplicationInfo.cs
- ImageInfo.cs
- ConnectionManagementElementCollection.cs
- IndexerNameAttribute.cs
- ListDictionaryInternal.cs
- TypefaceCollection.cs
- ExtensionDataReader.cs
- RandomNumberGenerator.cs
- TextDecorationCollection.cs
- SimpleHandlerFactory.cs
- DataGridViewRowsAddedEventArgs.cs
- OdbcPermission.cs
- PropertyInfoSet.cs
- SystemException.cs
- FormsAuthenticationCredentials.cs
- MimeReflector.cs
- XmlDataLoader.cs
- HtmlTableRow.cs
- Certificate.cs
- MasterPage.cs
- UnionExpr.cs
- WorkflowExecutor.cs
- XmlHelper.cs
- WhitespaceReader.cs
- ObjectAnimationBase.cs
- ConnectionsZone.cs
- ZipIOCentralDirectoryBlock.cs
- IntersectQueryOperator.cs
- XsdValidatingReader.cs
- SessionStateSection.cs
- OrthographicCamera.cs
- PolyQuadraticBezierSegment.cs
- NameValueFileSectionHandler.cs
- MetadataCache.cs
- PathStreamGeometryContext.cs
- AssemblyAssociatedContentFileAttribute.cs
- TimelineGroup.cs
- TableLayout.cs
- HostedImpersonationContext.cs
- HtmlFormParameterWriter.cs
- FontNameConverter.cs
- ExceptionUtil.cs
- Attributes.cs
- Transform.cs
- FontDialog.cs
- RoutedEventConverter.cs
- PropertyGridEditorPart.cs
- AssemblyName.cs
- Update.cs
- Annotation.cs
- DBNull.cs
- UniqueConstraint.cs
- XPathCompileException.cs
- BrowserCapabilitiesFactory.cs
- StringCollection.cs
- StringInfo.cs
- VectorAnimationUsingKeyFrames.cs
- ImageSourceTypeConverter.cs
- InstanceOwner.cs
- EvidenceBase.cs
- AuthenticateEventArgs.cs
- Registry.cs
- TCPClient.cs
- PostBackTrigger.cs
- Soap.cs