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
- Shared.cs
- Sql8ConformanceChecker.cs
- CryptoApi.cs
- ToolBarOverflowPanel.cs
- entitydatasourceentitysetnameconverter.cs
- DbConnectionPoolGroup.cs
- HighContrastHelper.cs
- EventLogException.cs
- Base64Stream.cs
- LineSegment.cs
- NetworkInformationException.cs
- QueryHandler.cs
- TextEditorParagraphs.cs
- WebPermission.cs
- ClientApiGenerator.cs
- StringUtil.cs
- WebBaseEventKeyComparer.cs
- Literal.cs
- FamilyTypeface.cs
- ListCollectionView.cs
- TextWriter.cs
- CryptoHelper.cs
- Model3DGroup.cs
- VectorCollectionConverter.cs
- NativeObjectSecurity.cs
- AxisAngleRotation3D.cs
- EntityDesignerUtils.cs
- GcHandle.cs
- NameTable.cs
- DataSourceHelper.cs
- OleDbConnectionFactory.cs
- SQLGuidStorage.cs
- RichTextBoxAutomationPeer.cs
- StringResourceManager.cs
- EventHandlers.cs
- ExceptionHandler.cs
- PopupControlService.cs
- PageCatalogPart.cs
- MetadataArtifactLoader.cs
- WebDisplayNameAttribute.cs
- ContractMapping.cs
- HtmlInputFile.cs
- TimeZone.cs
- FormatVersion.cs
- Help.cs
- XmlUtf8RawTextWriter.cs
- Contracts.cs
- WpfGeneratedKnownTypes.cs
- ObjectViewFactory.cs
- DataTableReaderListener.cs
- CloudCollection.cs
- UniqueSet.cs
- ToggleButtonAutomationPeer.cs
- StateRuntime.cs
- SettingsPropertyNotFoundException.cs
- EncodingTable.cs
- GridSplitterAutomationPeer.cs
- StringConverter.cs
- dtdvalidator.cs
- OdbcUtils.cs
- figurelength.cs
- TextElementAutomationPeer.cs
- SiteMapPath.cs
- CompilerGeneratedAttribute.cs
- ApplicationServiceManager.cs
- InstanceCreationEditor.cs
- NetSectionGroup.cs
- ProtocolsConfigurationHandler.cs
- TcpClientChannel.cs
- WorkflowPrinting.cs
- SupportingTokenChannel.cs
- HasActivatableWorkflowEvent.cs
- ThemeDirectoryCompiler.cs
- ParsedAttributeCollection.cs
- EventRoute.cs
- XamlParser.cs
- TransformerTypeCollection.cs
- SmiXetterAccessMap.cs
- InputScopeConverter.cs
- Merger.cs
- CryptoStream.cs
- KeyFrames.cs
- ContentElementAutomationPeer.cs
- TextSelectionHelper.cs
- SecurityHelper.cs
- TextSelectionProcessor.cs
- UpDownBaseDesigner.cs
- TriggerBase.cs
- FormatConvertedBitmap.cs
- querybuilder.cs
- SchemaImporter.cs
- DataGridViewCellCancelEventArgs.cs
- StreamWithDictionary.cs
- IndependentlyAnimatedPropertyMetadata.cs
- TdsParserStaticMethods.cs
- EventDescriptor.cs
- SelectionListDesigner.cs
- Vector3DValueSerializer.cs
- TrustManagerPromptUI.cs
- PagerSettings.cs