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
- KeyGestureConverter.cs
- DescendantQuery.cs
- ResizeGrip.cs
- grammarelement.cs
- RuleSettings.cs
- CFStream.cs
- TypeLoadException.cs
- Bitmap.cs
- DSACryptoServiceProvider.cs
- ExpandedProjectionNode.cs
- Win32NamedPipes.cs
- ConfigUtil.cs
- GenericTypeParameterBuilder.cs
- CompressionTransform.cs
- DataColumnCollection.cs
- GeneralTransform3D.cs
- Function.cs
- TextBoxRenderer.cs
- SerTrace.cs
- DateTimeFormatInfo.cs
- EdmToObjectNamespaceMap.cs
- _BaseOverlappedAsyncResult.cs
- TagPrefixCollection.cs
- LayoutInformation.cs
- ClientOperationFormatterProvider.cs
- AssemblyBuilder.cs
- CodeConstructor.cs
- peernodeimplementation.cs
- RegexCompilationInfo.cs
- HotCommands.cs
- NullExtension.cs
- MetadataItem.cs
- BinaryFormatterSinks.cs
- ModelEditingScope.cs
- NativeRightsManagementAPIsStructures.cs
- X509UI.cs
- InsufficientExecutionStackException.cs
- DbTransaction.cs
- WebConfigurationHostFileChange.cs
- RotateTransform3D.cs
- SoapFault.cs
- COM2ExtendedTypeConverter.cs
- DataMisalignedException.cs
- MgmtConfigurationRecord.cs
- HtmlLiteralTextAdapter.cs
- StorageEntitySetMapping.cs
- FunctionUpdateCommand.cs
- WSDualHttpSecurityMode.cs
- BulletedListEventArgs.cs
- HtmlInputReset.cs
- Camera.cs
- OutputCacheProfileCollection.cs
- CodeGroup.cs
- MouseActionConverter.cs
- DataBoundControl.cs
- CorePropertiesFilter.cs
- ConnectionStringSettingsCollection.cs
- RectangleF.cs
- GridViewAutoFormat.cs
- ParagraphVisual.cs
- TriState.cs
- ListBoxChrome.cs
- DataRecordInternal.cs
- OracleCommandBuilder.cs
- XmlSchemaSimpleContentExtension.cs
- DataGridItemAutomationPeer.cs
- HashSetDebugView.cs
- InstanceLockException.cs
- XmlSchemaAppInfo.cs
- WebPartActionVerb.cs
- DataGridViewCellConverter.cs
- AttachedPropertiesService.cs
- SocketInformation.cs
- StoreItemCollection.cs
- MTConfigUtil.cs
- XsdCachingReader.cs
- TextDecorationCollection.cs
- TreeNodeBindingDepthConverter.cs
- AsymmetricAlgorithm.cs
- IsolatedStorage.cs
- SendingRequestEventArgs.cs
- PageBreakRecord.cs
- EmissiveMaterial.cs
- CurrentChangedEventManager.cs
- EditorPartCollection.cs
- HtmlElementCollection.cs
- DataSourceCache.cs
- MessageDesigner.cs
- AssignDesigner.xaml.cs
- XmlSchemaChoice.cs
- ItemsPresenter.cs
- Point4D.cs
- JpegBitmapDecoder.cs
- dataprotectionpermissionattribute.cs
- TaskForm.cs
- XmlComment.cs
- FontStretches.cs
- EdmType.cs
- FileClassifier.cs
- GridViewRowPresenterBase.cs