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
- GridViewEditEventArgs.cs
- XamlRtfConverter.cs
- XsltQilFactory.cs
- ContractTypeNameElement.cs
- FrugalMap.cs
- ZoomPercentageConverter.cs
- StylusCollection.cs
- RegexStringValidatorAttribute.cs
- SqlConnectionHelper.cs
- CheckBox.cs
- XmlILModule.cs
- SmiContextFactory.cs
- DbgUtil.cs
- ExpressionsCollectionEditor.cs
- BindingSource.cs
- TextElementAutomationPeer.cs
- TypeHelper.cs
- CodeDirectoryCompiler.cs
- EventLogException.cs
- QueryGenerator.cs
- TouchesOverProperty.cs
- BidOverLoads.cs
- Stylesheet.cs
- WebCategoryAttribute.cs
- ListViewDataItem.cs
- QueryInterceptorAttribute.cs
- EdmToObjectNamespaceMap.cs
- ToolStripDropDownButton.cs
- PersistenceProviderElement.cs
- unitconverter.cs
- XmlDictionary.cs
- DataIdProcessor.cs
- SystemIPGlobalStatistics.cs
- TransactionFilter.cs
- DeviceContext2.cs
- NotifyInputEventArgs.cs
- UIElement.cs
- ContextMenuService.cs
- DbProviderSpecificTypePropertyAttribute.cs
- PackageDigitalSignatureManager.cs
- GenericIdentity.cs
- CqlErrorHelper.cs
- GenericEnumerator.cs
- DefaultValueMapping.cs
- GC.cs
- MulticastNotSupportedException.cs
- RegisteredScript.cs
- SafeArrayRankMismatchException.cs
- ObjectCacheSettings.cs
- SmtpClient.cs
- DelegatingTypeDescriptionProvider.cs
- ListViewGroupItemCollection.cs
- Native.cs
- ProcessModule.cs
- NativeMethods.cs
- TraceSwitch.cs
- Vector3DAnimationUsingKeyFrames.cs
- Exceptions.cs
- PeerApplication.cs
- SchemaDeclBase.cs
- TaskFileService.cs
- StorageMappingFragment.cs
- CatalogPartCollection.cs
- XmlNamespaceMappingCollection.cs
- sortedlist.cs
- RecordManager.cs
- HtmlInputImage.cs
- RequestStatusBarUpdateEventArgs.cs
- TraceContextEventArgs.cs
- hebrewshape.cs
- InfoCardMasterKey.cs
- OleDbDataAdapter.cs
- KeySpline.cs
- CssStyleCollection.cs
- BaseAddressPrefixFilterElementCollection.cs
- GenericRootAutomationPeer.cs
- Floater.cs
- WebPartRestoreVerb.cs
- TypedTableBase.cs
- Formatter.cs
- SpeakInfo.cs
- MenuItemCollection.cs
- TimeZone.cs
- Variant.cs
- Helpers.cs
- AsymmetricSignatureDeformatter.cs
- Permission.cs
- HandlerBase.cs
- StorageConditionPropertyMapping.cs
- isolationinterop.cs
- SettingsPropertyCollection.cs
- FrameworkContentElementAutomationPeer.cs
- MDIClient.cs
- SqlDeflator.cs
- TypeElement.cs
- SystemNetHelpers.cs
- ReadOnlyDictionary.cs
- StoreConnection.cs
- DiscardableAttribute.cs
- CommonXSendMessage.cs