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
- OdbcCommandBuilder.cs
- XmlDataSourceNodeDescriptor.cs
- Error.cs
- PixelShader.cs
- SqlDelegatedTransaction.cs
- DiscoveryDocumentLinksPattern.cs
- GridViewSortEventArgs.cs
- EventManager.cs
- LineBreakRecord.cs
- DynamicResourceExtensionConverter.cs
- PassportAuthenticationEventArgs.cs
- _LocalDataStoreMgr.cs
- CodeGenerator.cs
- ProcessHostServerConfig.cs
- TextRangeEditTables.cs
- ScriptRef.cs
- UrlMapping.cs
- BuilderInfo.cs
- Int32RectConverter.cs
- RemoteTokenFactory.cs
- TextTreeTextElementNode.cs
- Graph.cs
- PhonemeConverter.cs
- DependentList.cs
- StringBuilder.cs
- CreateParams.cs
- FilterEventArgs.cs
- CopyOfAction.cs
- XmlSubtreeReader.cs
- DelegateBodyWriter.cs
- DataServiceStreamProviderWrapper.cs
- WebConfigurationFileMap.cs
- Automation.cs
- EntityKeyElement.cs
- ApplicationFileParser.cs
- Wizard.cs
- XmlArrayItemAttributes.cs
- BatchParser.cs
- CaseCqlBlock.cs
- sqlser.cs
- DeclaredTypeValidator.cs
- SiteMapNodeItemEventArgs.cs
- BitmapEffectInput.cs
- MethodToken.cs
- XmlNodeReader.cs
- SmiRequestExecutor.cs
- HwndSourceKeyboardInputSite.cs
- CallSiteBinder.cs
- MissingMemberException.cs
- IERequestCache.cs
- SHA256Managed.cs
- Itemizer.cs
- IdentityReference.cs
- PropertyEmitter.cs
- ProcessHost.cs
- DynamicObject.cs
- DocumentViewerBase.cs
- DocumentAutomationPeer.cs
- TableAdapterManagerHelper.cs
- BufferModesCollection.cs
- ThicknessAnimation.cs
- BaseAddressElement.cs
- DataGridViewAccessibleObject.cs
- OrderedDictionary.cs
- RelatedView.cs
- XmlDocumentViewSchema.cs
- Pick.cs
- ConsoleTraceListener.cs
- SqlConnectionPoolGroupProviderInfo.cs
- RelationshipFixer.cs
- Base64Encoder.cs
- RayMeshGeometry3DHitTestResult.cs
- ScriptingProfileServiceSection.cs
- AppDomainCompilerProxy.cs
- TypeFieldSchema.cs
- KnownIds.cs
- FileAuthorizationModule.cs
- RegistryPermission.cs
- RectAnimation.cs
- StringKeyFrameCollection.cs
- FullTrustAssembly.cs
- _NativeSSPI.cs
- KeyProperty.cs
- ActivityTypeDesigner.xaml.cs
- NativeStructs.cs
- CqlWriter.cs
- SqlCaseSimplifier.cs
- WebBrowsableAttribute.cs
- KeyboardDevice.cs
- Transform3DGroup.cs
- SchemaTableColumn.cs
- ComplexBindingPropertiesAttribute.cs
- DesignerPerfEventProvider.cs
- SubtreeProcessor.cs
- PropertyChangeTracker.cs
- Divide.cs
- StrokeCollection.cs
- DataGridTextBoxColumn.cs
- _TLSstream.cs
- WS2007FederationHttpBindingCollectionElement.cs