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
- UIEndRequest.cs
- Console.cs
- NameObjectCollectionBase.cs
- GeneralTransform3DGroup.cs
- NestedContainer.cs
- TagMapInfo.cs
- ToolStripProgressBar.cs
- XmlSchemaExporter.cs
- ScriptRegistrationManager.cs
- HttpMethodConstraint.cs
- MenuItemCollectionEditorDialog.cs
- XmlNode.cs
- SafeNativeMethodsOther.cs
- FontDifferentiator.cs
- RtfToken.cs
- ApplicationContext.cs
- DATA_BLOB.cs
- Avt.cs
- ExternalException.cs
- RegexMatch.cs
- ProxyAttribute.cs
- CreateWorkflowOwnerCommand.cs
- mediapermission.cs
- OutputCacheSettingsSection.cs
- ZipArchive.cs
- _AuthenticationState.cs
- FontCollection.cs
- PipelineModuleStepContainer.cs
- Expander.cs
- SequenceDesigner.cs
- DictionaryBase.cs
- Int32CAMarshaler.cs
- RegisteredExpandoAttribute.cs
- TreeNode.cs
- HwndSourceKeyboardInputSite.cs
- MenuItemCollectionEditorDialog.cs
- ArrayElementGridEntry.cs
- HtmlInputPassword.cs
- AssemblyCollection.cs
- ArglessEventHandlerProxy.cs
- XmlSchemaCompilationSettings.cs
- TrackingMemoryStream.cs
- ProcessHostServerConfig.cs
- RequestTimeoutManager.cs
- HttpResponse.cs
- FormatConvertedBitmap.cs
- EntityDataSourceConfigureObjectContext.cs
- BindingValueChangedEventArgs.cs
- XmlReaderSettings.cs
- ItemMap.cs
- UInt64.cs
- RegexBoyerMoore.cs
- TableLayout.cs
- RecordsAffectedEventArgs.cs
- AnnotationComponentManager.cs
- Message.cs
- SimpleFieldTemplateUserControl.cs
- _NegoState.cs
- SQLChars.cs
- XmlValueConverter.cs
- WebScriptEndpoint.cs
- ProcessProtocolHandler.cs
- ContextMenu.cs
- AssemblyCacheEntry.cs
- Version.cs
- NegotiateStream.cs
- TreeNodeStyle.cs
- InheritanceContextChangedEventManager.cs
- ObjectQuery_EntitySqlExtensions.cs
- SmtpException.cs
- PeerName.cs
- SeekableReadStream.cs
- Clause.cs
- AsymmetricKeyExchangeDeformatter.cs
- SoundPlayerAction.cs
- ShapingEngine.cs
- SetterTriggerConditionValueConverter.cs
- ChannelManager.cs
- ProbeMatchesMessage11.cs
- BuildProviderAppliesToAttribute.cs
- DataSvcMapFile.cs
- cryptoapiTransform.cs
- HashSet.cs
- TrustLevel.cs
- TextEditorContextMenu.cs
- DefaultObjectMappingItemCollection.cs
- OutOfProcStateClientManager.cs
- FeatureSupport.cs
- GridViewColumnHeader.cs
- Bits.cs
- InternalTypeHelper.cs
- ServiceObjectContainer.cs
- IisTraceListener.cs
- entityreference_tresulttype.cs
- IdnElement.cs
- SupportsEventValidationAttribute.cs
- CompositeCollection.cs
- Variable.cs
- StrokeNodeOperations2.cs
- StatusInfoItem.cs