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
- Activator.cs
- PagePropertiesChangingEventArgs.cs
- MappingModelBuildProvider.cs
- InvalidFilterCriteriaException.cs
- VariableQuery.cs
- DeobfuscatingStream.cs
- Helper.cs
- DesignerVerb.cs
- ValidateNames.cs
- PropertyInformationCollection.cs
- JoinTreeNode.cs
- ParameterBinding.cs
- XmlDownloadManager.cs
- DataBinding.cs
- StrokeNodeData.cs
- ConnectionsZoneDesigner.cs
- DragEventArgs.cs
- RuleRefElement.cs
- __TransparentProxy.cs
- ObjectNavigationPropertyMapping.cs
- ConfigurationLocationCollection.cs
- GuidelineCollection.cs
- ButtonStandardAdapter.cs
- UrlUtility.cs
- FreezableCollection.cs
- QuaternionAnimation.cs
- AssemblyCache.cs
- FrameworkElement.cs
- EntityDescriptor.cs
- InfoCardSymmetricCrypto.cs
- DbUpdateCommandTree.cs
- XmlSchemaRedefine.cs
- MouseWheelEventArgs.cs
- IdnMapping.cs
- NetworkCredential.cs
- WebServiceErrorEvent.cs
- TreeView.cs
- Zone.cs
- WebPartManagerDesigner.cs
- ReadOnlyDataSource.cs
- FileSystemEnumerable.cs
- HtmlInputControl.cs
- HitTestParameters3D.cs
- CircleEase.cs
- NetworkAddressChange.cs
- ImageBrush.cs
- ParentUndoUnit.cs
- IndexedEnumerable.cs
- WSTrustFeb2005.cs
- Documentation.cs
- ConsoleTraceListener.cs
- StorageEntityContainerMapping.cs
- PageContentAsyncResult.cs
- Pointer.cs
- XPathDocumentIterator.cs
- TokenBasedSet.cs
- DispatcherEventArgs.cs
- CngProperty.cs
- BamlRecords.cs
- XmlRootAttribute.cs
- CodeGotoStatement.cs
- ClientUrlResolverWrapper.cs
- WindowsPrincipal.cs
- ErrorLog.cs
- ADMembershipProvider.cs
- Region.cs
- EdmPropertyAttribute.cs
- Set.cs
- Font.cs
- ObjectViewFactory.cs
- ControlsConfig.cs
- SQLGuidStorage.cs
- WindowsFont.cs
- HostedNamedPipeTransportManager.cs
- SQLSingle.cs
- SerializationFieldInfo.cs
- PolygonHotSpot.cs
- CodeTypeMemberCollection.cs
- SizeAnimationBase.cs
- EnumMember.cs
- DynamicILGenerator.cs
- ForEachAction.cs
- KeyInterop.cs
- DragCompletedEventArgs.cs
- util.cs
- dbenumerator.cs
- XmlImplementation.cs
- SQLDecimal.cs
- BamlCollectionHolder.cs
- Root.cs
- Section.cs
- EventHandlers.cs
- EmptyStringExpandableObjectConverter.cs
- XmlWhitespace.cs
- ImageAnimator.cs
- DataRecordObjectView.cs
- UITypeEditor.cs
- CustomAttribute.cs
- Selector.cs
- GenericNameHandler.cs