Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- EllipseGeometry.cs
- XamlSerializerUtil.cs
- SyncMethodInvoker.cs
- SecurityHeaderElementInferenceEngine.cs
- ModulesEntry.cs
- Context.cs
- GridViewSelectEventArgs.cs
- ZipIOCentralDirectoryFileHeader.cs
- InternalDispatchObject.cs
- base64Transforms.cs
- PersonalizableAttribute.cs
- SettingsPropertyCollection.cs
- TextParaLineResult.cs
- DataContractAttribute.cs
- ThumbAutomationPeer.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- RelationHandler.cs
- JsonClassDataContract.cs
- StylusTip.cs
- XmlSchemaAnnotation.cs
- StaticExtension.cs
- BooleanToVisibilityConverter.cs
- CanonicalXml.cs
- ECDiffieHellmanCng.cs
- SecurityManager.cs
- DecoderFallbackWithFailureFlag.cs
- SerializerDescriptor.cs
- UnderstoodHeaders.cs
- WizardPanelChangingEventArgs.cs
- TimeManager.cs
- HScrollProperties.cs
- MetadataPropertyCollection.cs
- safesecurityhelperavalon.cs
- ClientScriptManager.cs
- OrderedHashRepartitionEnumerator.cs
- XamlReader.cs
- Visual3DCollection.cs
- TreeView.cs
- Pen.cs
- RijndaelManaged.cs
- InertiaRotationBehavior.cs
- RequestCachePolicyConverter.cs
- CustomAttributeFormatException.cs
- DetailsViewDeletedEventArgs.cs
- ServiceDescription.cs
- WizardStepBase.cs
- NCryptSafeHandles.cs
- FileUtil.cs
- DataSvcMapFileSerializer.cs
- NotImplementedException.cs
- OptimisticConcurrencyException.cs
- SemanticBasicElement.cs
- IProvider.cs
- StylusPointPropertyInfoDefaults.cs
- ObjectDataSourceSelectingEventArgs.cs
- ExpressionDumper.cs
- TabItemAutomationPeer.cs
- Marshal.cs
- DbDataRecord.cs
- SspiSafeHandles.cs
- AutomationPropertyInfo.cs
- BitStack.cs
- __Filters.cs
- CookieProtection.cs
- Variable.cs
- EventlogProvider.cs
- EpmContentDeSerializer.cs
- CanExpandCollapseAllConverter.cs
- AttachmentCollection.cs
- CommandHelpers.cs
- CodePageEncoding.cs
- SqlCommandBuilder.cs
- WhileDesigner.cs
- DbConnectionStringBuilder.cs
- XmlConvert.cs
- KerberosTokenFactoryCredential.cs
- CodeNamespaceImport.cs
- wgx_exports.cs
- MetabaseServerConfig.cs
- AstTree.cs
- SurrogateSelector.cs
- HtmlInputSubmit.cs
- MatrixUtil.cs
- wgx_exports.cs
- TransformGroup.cs
- DefaultPropertyAttribute.cs
- BaseValidator.cs
- WrappedKeySecurityToken.cs
- arclist.cs
- StorageEntityTypeMapping.cs
- ScriptResourceInfo.cs
- DateTimeEditor.cs
- DataGridColumnFloatingHeader.cs
- UnaryNode.cs
- TextWriter.cs
- XmlSerializationWriter.cs
- ScrollBar.cs
- EntityDataSourceDesignerHelper.cs
- StringValueConverter.cs
- SqlTypeConverter.cs