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
- TCPListener.cs
- OdbcCommandBuilder.cs
- TableLayoutSettings.cs
- DictionaryBase.cs
- ByteStorage.cs
- Dump.cs
- HttpCookieCollection.cs
- FrameworkContextData.cs
- Descriptor.cs
- DispatchOperationRuntime.cs
- XamlInt32CollectionSerializer.cs
- TraceHandlerErrorFormatter.cs
- CapabilitiesAssignment.cs
- MissingMethodException.cs
- XmlSchemaImporter.cs
- PeerEndPoint.cs
- SqlDependencyUtils.cs
- DateTimeUtil.cs
- BrowserDefinitionCollection.cs
- KeyNotFoundException.cs
- UncommonField.cs
- XmlDocumentSchema.cs
- TriState.cs
- BitmapEffectInput.cs
- SkipStoryboardToFill.cs
- SafeBitVector32.cs
- LocalsItemDescription.cs
- ArrayWithOffset.cs
- SortedDictionary.cs
- InvokeWebServiceDesigner.cs
- GeneralTransform3DGroup.cs
- SchemaHelper.cs
- EncodingInfo.cs
- DataGridViewTextBoxCell.cs
- Errors.cs
- DescriptionAttribute.cs
- StateManagedCollection.cs
- AcceptorSessionSymmetricTransportSecurityProtocol.cs
- UIPermission.cs
- GlyphRun.cs
- ShapingEngine.cs
- ProxyWebPart.cs
- WebServiceParameterData.cs
- PageEventArgs.cs
- XmlQueryStaticData.cs
- ShaderRenderModeValidation.cs
- UnsafeNativeMethods.cs
- AsyncCompletedEventArgs.cs
- FieldMetadata.cs
- SignedPkcs7.cs
- ResourceDictionary.cs
- StructuralType.cs
- Line.cs
- ClientConvert.cs
- WebPartDescription.cs
- EdmToObjectNamespaceMap.cs
- PropertyPath.cs
- StrongNameMembershipCondition.cs
- PrivateUnsafeNativeCompoundFileMethods.cs
- ApplicationManager.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- TimeSpanStorage.cs
- CompositeControl.cs
- IDictionary.cs
- MediaTimeline.cs
- RuntimeConfig.cs
- ModelItemKeyValuePair.cs
- BinaryUtilClasses.cs
- StringDictionaryEditor.cs
- SectionVisual.cs
- StrokeNodeEnumerator.cs
- NativeMethods.cs
- FieldToken.cs
- ControlCodeDomSerializer.cs
- Typography.cs
- GeneralTransform2DTo3DTo2D.cs
- ModifierKeysValueSerializer.cs
- ProtocolViolationException.cs
- CodeCommentStatement.cs
- BinaryUtilClasses.cs
- RouteData.cs
- ToolStripRenderEventArgs.cs
- ping.cs
- NavigationProperty.cs
- Attributes.cs
- SQLConvert.cs
- AnnotationResource.cs
- DefaultPropertiesToSend.cs
- WorkflowTransactionOptions.cs
- InvalidAsynchronousStateException.cs
- SimpleRecyclingCache.cs
- TextElementCollectionHelper.cs
- SoapSchemaMember.cs
- FlowDocumentFormatter.cs
- RotateTransform.cs
- QueueProcessor.cs
- ResourceDictionaryCollection.cs
- SqlUserDefinedTypeAttribute.cs
- XslAstAnalyzer.cs
- XmlCodeExporter.cs