Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / Microsoft / Win32 / SafeNativeMemoryHandle.cs / 1305376 / 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
- ExecutionEngineException.cs
- AuthenticationConfig.cs
- ParserExtension.cs
- ExpressionWriter.cs
- EntityAdapter.cs
- AlternateViewCollection.cs
- IndependentAnimationStorage.cs
- ImageSourceConverter.cs
- EnumerableCollectionView.cs
- XmlSchemaCollection.cs
- DoubleAnimationUsingKeyFrames.cs
- FileSystemEventArgs.cs
- TableAdapterManagerHelper.cs
- InputLanguageEventArgs.cs
- MDIClient.cs
- WebEventCodes.cs
- DataColumnChangeEvent.cs
- sqlinternaltransaction.cs
- Menu.cs
- WebPartDeleteVerb.cs
- SamlAuthorizationDecisionStatement.cs
- BaseTemplateBuildProvider.cs
- HttpResponseInternalWrapper.cs
- Merger.cs
- HostingEnvironmentWrapper.cs
- HtmlControlAdapter.cs
- XmlWriterSettings.cs
- UriSection.cs
- SystemIPAddressInformation.cs
- ReservationCollection.cs
- ReversePositionQuery.cs
- HWStack.cs
- XmlSchemaSubstitutionGroup.cs
- SmiXetterAccessMap.cs
- PageThemeParser.cs
- XmlLoader.cs
- PersonalizationStateInfoCollection.cs
- SafeProcessHandle.cs
- CodeVariableReferenceExpression.cs
- WebPartVerbCollection.cs
- ServicePerformanceCounters.cs
- WebPartEventArgs.cs
- PassportAuthentication.cs
- RegistrationServices.cs
- ResolveMatchesMessageCD1.cs
- CryptoStream.cs
- ReadOnlyCollectionBase.cs
- MenuItemBinding.cs
- ConfigurationHelpers.cs
- Splitter.cs
- CommandBinding.cs
- RubberbandSelector.cs
- DataFieldConverter.cs
- XamlGridLengthSerializer.cs
- SqlRemoveConstantOrderBy.cs
- updatecommandorderer.cs
- ColorDialog.cs
- RSAPKCS1SignatureFormatter.cs
- linebase.cs
- ZipIOCentralDirectoryFileHeader.cs
- AssemblyBuilderData.cs
- EmbeddedObject.cs
- externdll.cs
- WinInet.cs
- UriScheme.cs
- DisplayNameAttribute.cs
- AppDomainProtocolHandler.cs
- PerfCounterSection.cs
- SafeHandles.cs
- WebPartCatalogAddVerb.cs
- HtmlEmptyTagControlBuilder.cs
- TextPointerBase.cs
- ApplicationDirectory.cs
- RoleBoolean.cs
- IDReferencePropertyAttribute.cs
- UseLicense.cs
- IMembershipProvider.cs
- OleDbDataReader.cs
- SqlProfileProvider.cs
- errorpatternmatcher.cs
- AmbientEnvironment.cs
- XPathScanner.cs
- CqlIdentifiers.cs
- EventLog.cs
- RuntimeArgumentHandle.cs
- DataSourceCache.cs
- Console.cs
- GifBitmapEncoder.cs
- StyleCollectionEditor.cs
- RequestResizeEvent.cs
- ContractNamespaceAttribute.cs
- DataGridViewBand.cs
- XmlSchemaComplexType.cs
- SchemaObjectWriter.cs
- SimpleType.cs
- Int32AnimationUsingKeyFrames.cs
- HashHelper.cs
- NamespaceInfo.cs
- Int32Storage.cs
- ResourceExpressionBuilder.cs