Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- SerializeAbsoluteContext.cs
- QueryCacheEntry.cs
- IpcClientManager.cs
- RequestCachePolicy.cs
- Queue.cs
- xamlnodes.cs
- _ServiceNameStore.cs
- HttpCacheParams.cs
- ActivationArguments.cs
- TypeConverterMarkupExtension.cs
- DbProviderConfigurationHandler.cs
- XmlAttributeOverrides.cs
- DBParameter.cs
- ValueExpressions.cs
- EnumConverter.cs
- Point3DAnimation.cs
- PropertyValueUIItem.cs
- InfoCardTrace.cs
- VisualStyleRenderer.cs
- SafeNativeMethods.cs
- embossbitmapeffect.cs
- EncodingDataItem.cs
- Triplet.cs
- AnonymousIdentificationSection.cs
- TransformedBitmap.cs
- CorePropertiesFilter.cs
- NegotiationTokenAuthenticator.cs
- UnsignedPublishLicense.cs
- ASCIIEncoding.cs
- DropShadowBitmapEffect.cs
- CmsUtils.cs
- HtmlButton.cs
- DataGridViewComboBoxEditingControl.cs
- ListView.cs
- PropertyCollection.cs
- Soap12FormatExtensions.cs
- ElementsClipboardData.cs
- activationcontext.cs
- DataGridViewSelectedCellCollection.cs
- TreeNodeMouseHoverEvent.cs
- InheritablePropertyChangeInfo.cs
- DataListItem.cs
- GenericAuthenticationEventArgs.cs
- DockingAttribute.cs
- NativeMethods.cs
- Atom10FormatterFactory.cs
- LinkedResource.cs
- ProcessModuleCollection.cs
- TextServicesDisplayAttributePropertyRanges.cs
- DragAssistanceManager.cs
- Cursor.cs
- serverconfig.cs
- SkewTransform.cs
- SimpleTypeResolver.cs
- DataSysAttribute.cs
- ImmutableDispatchRuntime.cs
- DataGridViewLinkCell.cs
- And.cs
- RuntimeUtils.cs
- IdentityReference.cs
- Keyboard.cs
- WpfKnownMemberInvoker.cs
- ProfileService.cs
- ForeignConstraint.cs
- SQLInt32.cs
- OdbcDataReader.cs
- SqlColumnizer.cs
- LocalValueEnumerator.cs
- ContentControl.cs
- ExpressionParser.cs
- XhtmlBasicValidationSummaryAdapter.cs
- DocobjHost.cs
- arclist.cs
- UserControlParser.cs
- ProfileSection.cs
- Matrix3D.cs
- FontConverter.cs
- HwndSubclass.cs
- ISAPIRuntime.cs
- WsdlImporter.cs
- ActivationServices.cs
- NodeLabelEditEvent.cs
- LayoutEvent.cs
- NumericUpDownAcceleration.cs
- BaseComponentEditor.cs
- BidPrivateBase.cs
- QueueProcessor.cs
- brushes.cs
- Random.cs
- ExecutionEngineException.cs
- DataObjectAttribute.cs
- EmptyEnumerator.cs
- EditBehavior.cs
- SqlErrorCollection.cs
- ServicesUtilities.cs
- MediaTimeline.cs
- SqlBuilder.cs
- XXXInfos.cs
- LinqDataView.cs
- UrlMappingsModule.cs