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
- Process.cs
- DataGridCellsPanel.cs
- ACE.cs
- DummyDataSource.cs
- ProvideValueServiceProvider.cs
- PhysicalFontFamily.cs
- KeyValuePair.cs
- IntSecurity.cs
- ImageButton.cs
- RadioButton.cs
- LicenseException.cs
- Button.cs
- RightsManagementInformation.cs
- SymbolType.cs
- WebHttpSecurityElement.cs
- RawStylusSystemGestureInputReport.cs
- DerivedKeyCachingSecurityTokenSerializer.cs
- TypeConverterAttribute.cs
- IDReferencePropertyAttribute.cs
- Certificate.cs
- MailAddressCollection.cs
- StylusEventArgs.cs
- ToolStripItemCollection.cs
- TextChange.cs
- MarkupExtensionSerializer.cs
- _ConnectOverlappedAsyncResult.cs
- GPRECTF.cs
- SystemInformation.cs
- NullableConverter.cs
- DataControlCommands.cs
- TextChangedEventArgs.cs
- UserControlDocumentDesigner.cs
- IFlowDocumentViewer.cs
- GeneralTransformGroup.cs
- CheckedListBox.cs
- FilterInvalidBodyAccessException.cs
- ListBase.cs
- WebBrowserBase.cs
- KeyValueConfigurationElement.cs
- PasswordBoxAutomationPeer.cs
- TreeBuilder.cs
- ChangeProcessor.cs
- OverflowException.cs
- BrushValueSerializer.cs
- XmlnsCompatibleWithAttribute.cs
- ChtmlTextWriter.cs
- EndEvent.cs
- TreeNodeStyleCollection.cs
- GeneralTransform3DTo2DTo3D.cs
- GridViewColumnCollection.cs
- DescendantBaseQuery.cs
- DropDownList.cs
- IriParsingElement.cs
- XamlVector3DCollectionSerializer.cs
- ConfigurationStrings.cs
- GroupBoxAutomationPeer.cs
- OlePropertyStructs.cs
- HierarchicalDataTemplate.cs
- RegistrySecurity.cs
- Point3D.cs
- CategoryAttribute.cs
- HtmlTableRowCollection.cs
- BlockUIContainer.cs
- LineVisual.cs
- PackagingUtilities.cs
- HTMLTextWriter.cs
- BulletChrome.cs
- AstNode.cs
- ScriptResourceInfo.cs
- Point3DCollection.cs
- MenuItem.cs
- BindMarkupExtensionSerializer.cs
- WebPartsSection.cs
- DataListComponentEditor.cs
- LoginStatusDesigner.cs
- NavigatorInput.cs
- BulletedListDesigner.cs
- XamlVector3DCollectionSerializer.cs
- FormatterConverter.cs
- ReverseQueryOperator.cs
- Thread.cs
- BamlMapTable.cs
- CodeSnippetStatement.cs
- FileUpload.cs
- SerialPort.cs
- DbUpdateCommandTree.cs
- HiddenFieldPageStatePersister.cs
- ProcessHost.cs
- SrgsRulesCollection.cs
- StdRegProviderWrapper.cs
- Internal.cs
- GeometryHitTestResult.cs
- ServiceDiscoveryBehavior.cs
- SQLDateTime.cs
- FileVersionInfo.cs
- CounterSample.cs
- TranslateTransform3D.cs
- CrossContextChannel.cs
- StoryFragments.cs
- StringToken.cs