Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- SkewTransform.cs
- SkewTransform.cs
- Application.cs
- LinqDataSourceValidationException.cs
- FtpCachePolicyElement.cs
- ActivityBindForm.cs
- PropertyEmitterBase.cs
- XmlTypeAttribute.cs
- UnionCqlBlock.cs
- LogicalExpr.cs
- PageCatalogPart.cs
- ExtenderControl.cs
- RenderingBiasValidation.cs
- DataGridSortingEventArgs.cs
- printdlgexmarshaler.cs
- SchemaCollectionCompiler.cs
- WizardStepBase.cs
- XMLSyntaxException.cs
- Transform3DGroup.cs
- IgnoreSection.cs
- SortedDictionary.cs
- Deserializer.cs
- AssertSection.cs
- TreeWalker.cs
- BaseCollection.cs
- BitmapMetadataEnumerator.cs
- ListBoxChrome.cs
- Point.cs
- ToolboxItem.cs
- ItemDragEvent.cs
- DoWorkEventArgs.cs
- MSAAEventDispatcher.cs
- BasicExpandProvider.cs
- CodeIdentifier.cs
- UTF32Encoding.cs
- RelationshipDetailsCollection.cs
- FileUtil.cs
- SoapFault.cs
- OpenCollectionAsyncResult.cs
- NamespaceDecl.cs
- EventLogTraceListener.cs
- DesignSurface.cs
- SimpleMailWebEventProvider.cs
- DataBoundControl.cs
- XmlCharType.cs
- AggregationMinMaxHelpers.cs
- EndpointAddressElementBase.cs
- WebSysDescriptionAttribute.cs
- DataGridViewCellCollection.cs
- PropertyPanel.cs
- AsnEncodedData.cs
- IndexedGlyphRun.cs
- RadioButton.cs
- CalendarBlackoutDatesCollection.cs
- ValidationError.cs
- HttpHandlersSection.cs
- CssTextWriter.cs
- VariableQuery.cs
- TypeLibConverter.cs
- SmtpReplyReader.cs
- BamlBinaryWriter.cs
- ADMembershipProvider.cs
- ThreadStartException.cs
- TokenizerHelper.cs
- ConstraintConverter.cs
- ExpressionParser.cs
- BasicKeyConstraint.cs
- IntSecurity.cs
- DateRangeEvent.cs
- CollectionViewGroupRoot.cs
- XmlChildEnumerator.cs
- ToolStripDropTargetManager.cs
- IdentifierCreationService.cs
- COSERVERINFO.cs
- ObjectStateManager.cs
- AlphabeticalEnumConverter.cs
- FullTextState.cs
- VerticalAlignConverter.cs
- SystemInformation.cs
- NavigatorInput.cs
- WindowVisualStateTracker.cs
- securestring.cs
- ListViewHitTestInfo.cs
- MetabaseSettingsIis7.cs
- TraceSection.cs
- DependencyPropertyConverter.cs
- AdRotator.cs
- RectangleF.cs
- ReadOnlyObservableCollection.cs
- SmtpException.cs
- SequenceDesigner.cs
- DataSourceCacheDurationConverter.cs
- VisualTarget.cs
- TabletCollection.cs
- ApplicationFileCodeDomTreeGenerator.cs
- XmlValidatingReaderImpl.cs
- HttpListenerResponse.cs
- Activator.cs
- DiscoveryClientOutputChannel.cs
- OdbcUtils.cs