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
- IIS7UserPrincipal.cs
- InvariantComparer.cs
- LineSegment.cs
- ObjectContextServiceProvider.cs
- MarkupProperty.cs
- DesignerRegion.cs
- ApplicationActivator.cs
- WindowsScrollBarBits.cs
- SubMenuStyleCollection.cs
- SignatureGenerator.cs
- ProfileSettings.cs
- ViewStateModeByIdAttribute.cs
- RawStylusInputCustomDataList.cs
- SharedPersonalizationStateInfo.cs
- BinHexEncoder.cs
- FieldCollectionEditor.cs
- PeerCollaboration.cs
- MsmqInputMessagePool.cs
- CriticalHandle.cs
- DataGridState.cs
- CodeDomConfigurationHandler.cs
- ImmutableObjectAttribute.cs
- StylusDownEventArgs.cs
- PresentationSource.cs
- MultipartContentParser.cs
- ParseNumbers.cs
- BitmapFrameDecode.cs
- EventSinkHelperWriter.cs
- ObjectSecurityT.cs
- MimeWriter.cs
- DiscoveryDocumentSearchPattern.cs
- ProcessModule.cs
- ImageMetadata.cs
- DrawingServices.cs
- SafeProcessHandle.cs
- ErrorsHelper.cs
- PerformanceCounterPermissionEntry.cs
- TdsParserStaticMethods.cs
- ComponentChangedEvent.cs
- AvTrace.cs
- RIPEMD160.cs
- ToggleButton.cs
- SynchronizedPool.cs
- GeometryHitTestResult.cs
- DefaultPropertiesToSend.cs
- DocumentSchemaValidator.cs
- XmlSigningNodeWriter.cs
- QueryContinueDragEventArgs.cs
- WebPartEventArgs.cs
- ToolStripItemTextRenderEventArgs.cs
- WindowsGraphics.cs
- CompatibleComparer.cs
- ModuleElement.cs
- BufferedGraphics.cs
- ApplyTemplatesAction.cs
- NavigationHelper.cs
- DateTimePicker.cs
- Oid.cs
- CopyOnWriteList.cs
- CssClassPropertyAttribute.cs
- HandleRef.cs
- StackBuilderSink.cs
- Image.cs
- EntityTypeEmitter.cs
- TCEAdapterGenerator.cs
- ILGenerator.cs
- PersonalizationEntry.cs
- SpecialNameAttribute.cs
- Schema.cs
- EventRoute.cs
- HtmlHead.cs
- Button.cs
- EUCJPEncoding.cs
- HostingEnvironmentSection.cs
- CompositeActivityDesigner.cs
- DesignOnlyAttribute.cs
- XmlSerializableWriter.cs
- SharedUtils.cs
- TimeZoneInfo.cs
- HttpsTransportElement.cs
- PlaceHolder.cs
- SymbolMethod.cs
- TimeIntervalCollection.cs
- SessionPageStatePersister.cs
- Module.cs
- TokenBasedSetEnumerator.cs
- InfoCardX509Validator.cs
- RegexTree.cs
- PrintingPermission.cs
- XPathBinder.cs
- ComplexBindingPropertiesAttribute.cs
- DataKeyArray.cs
- Ipv6Element.cs
- CssTextWriter.cs
- Int64Storage.cs
- IImplicitResourceProvider.cs
- ListViewItemMouseHoverEvent.cs
- ResourcesBuildProvider.cs
- PropertyTab.cs
- _IPv6Address.cs