Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- PageContentAsyncResult.cs
- DateTimeConverter2.cs
- DataServiceBuildProvider.cs
- DataViewListener.cs
- OleDbDataAdapter.cs
- ToolStripProgressBar.cs
- PickBranch.cs
- ScrollChrome.cs
- ImageResources.Designer.cs
- ChineseLunisolarCalendar.cs
- XmlBaseReader.cs
- WindowsListViewItem.cs
- TemplateBindingExtension.cs
- ModuleConfigurationInfo.cs
- MetadataFile.cs
- NameTable.cs
- XmlSchemaSequence.cs
- HttpHandlersInstallComponent.cs
- ControlBindingsCollection.cs
- OutKeywords.cs
- CreateUserWizard.cs
- StringResourceManager.cs
- PerfCounterSection.cs
- ToolStripScrollButton.cs
- DefaultValueConverter.cs
- PropertyPathWorker.cs
- BlockCollection.cs
- DnsEndPoint.cs
- StringComparer.cs
- OperatorExpressions.cs
- HttpCachePolicyWrapper.cs
- HttpCachePolicyElement.cs
- EntryPointNotFoundException.cs
- LinkGrep.cs
- HandlerBase.cs
- TextWriterTraceListener.cs
- SecurityDocument.cs
- ClientScriptManager.cs
- TemplatedAdorner.cs
- KerberosRequestorSecurityTokenAuthenticator.cs
- DrawingAttributeSerializer.cs
- CheckBoxBaseAdapter.cs
- FamilyTypeface.cs
- FrameworkPropertyMetadata.cs
- LinqToSqlWrapper.cs
- EditorAttributeInfo.cs
- CellQuery.cs
- StatusStrip.cs
- sqlpipe.cs
- _NTAuthentication.cs
- ListViewUpdatedEventArgs.cs
- AutomationEventArgs.cs
- TeredoHelper.cs
- CompositeKey.cs
- ByteConverter.cs
- TemplateBamlTreeBuilder.cs
- ColorMap.cs
- SettingsSection.cs
- LogExtentCollection.cs
- StaticExtension.cs
- BlockingCollection.cs
- BridgeDataRecord.cs
- Substitution.cs
- ArraySegment.cs
- CultureData.cs
- ArraySubsetEnumerator.cs
- PolicyStatement.cs
- IDQuery.cs
- WsatConfiguration.cs
- KeyEvent.cs
- CultureTable.cs
- PasswordPropertyTextAttribute.cs
- PageContentAsyncResult.cs
- StorageScalarPropertyMapping.cs
- CacheEntry.cs
- HttpCacheParams.cs
- TextParagraphView.cs
- AssociationSetMetadata.cs
- WebRequestModulesSection.cs
- BaseCodePageEncoding.cs
- XmlSchemaAttributeGroupRef.cs
- DecimalConstantAttribute.cs
- MonthChangedEventArgs.cs
- AsnEncodedData.cs
- Profiler.cs
- HashAlgorithm.cs
- DocobjHost.cs
- ComponentManagerBroker.cs
- PhysicalAddress.cs
- TextContainer.cs
- DataObjectAttribute.cs
- SiteMapHierarchicalDataSourceView.cs
- IdnElement.cs
- SafeSystemMetrics.cs
- WebBrowserUriTypeConverter.cs
- GridViewItemAutomationPeer.cs
- RowUpdatedEventArgs.cs
- MultiPropertyDescriptorGridEntry.cs
- ChildrenQuery.cs
- ConstraintEnumerator.cs