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
- ParsedAttributeCollection.cs
- SoapFault.cs
- _SslSessionsCache.cs
- controlskin.cs
- DbMetaDataColumnNames.cs
- IdentityModelDictionary.cs
- LinqDataSourceHelper.cs
- X509CertificateClaimSet.cs
- FormsAuthenticationEventArgs.cs
- GridViewSelectEventArgs.cs
- MultipartIdentifier.cs
- BamlRecordWriter.cs
- AccessDataSource.cs
- GZipUtils.cs
- EnumerableRowCollection.cs
- DesignOnlyAttribute.cs
- SegmentTree.cs
- SimplePropertyEntry.cs
- ResolveNameEventArgs.cs
- ChangePassword.cs
- XmlSerializerSection.cs
- DesignerOptionService.cs
- LicenseException.cs
- ProxyHwnd.cs
- CheckBoxBaseAdapter.cs
- PictureBox.cs
- UserControlCodeDomTreeGenerator.cs
- DataGridViewToolTip.cs
- CollectionEditVerbManager.cs
- processwaithandle.cs
- SchemaImporter.cs
- SplitterPanel.cs
- CodeTryCatchFinallyStatement.cs
- WindowsRichEditRange.cs
- Table.cs
- Container.cs
- NodeLabelEditEvent.cs
- ProjectionQueryOptionExpression.cs
- ExtensionFile.cs
- EventLogPermissionAttribute.cs
- CompositeFontFamily.cs
- ChannelManager.cs
- NamespaceCollection.cs
- SqlPersonalizationProvider.cs
- Utilities.cs
- AutoCompleteStringCollection.cs
- KnownTypesProvider.cs
- LocalBuilder.cs
- RtType.cs
- WebHttpBindingCollectionElement.cs
- DirtyTextRange.cs
- ServerTooBusyException.cs
- TextBox.cs
- RenderContext.cs
- StoreItemCollection.cs
- ConstraintStruct.cs
- GlyphingCache.cs
- DataControlImageButton.cs
- FontDriver.cs
- ToolStripRenderEventArgs.cs
- ElementHost.cs
- MessageSecurityVersionConverter.cs
- OdbcPermission.cs
- DataGridLength.cs
- RoutedPropertyChangedEventArgs.cs
- XmlILAnnotation.cs
- ContentValidator.cs
- TrackBarRenderer.cs
- HierarchicalDataTemplate.cs
- ThreadSafeList.cs
- XamlSerializerUtil.cs
- Decoder.cs
- ToolStripMenuItem.cs
- DataGridPageChangedEventArgs.cs
- EntityDataSourceDataSelection.cs
- MatrixAnimationUsingKeyFrames.cs
- RtfControlWordInfo.cs
- UnaryOperationBinder.cs
- DataBindingsDialog.cs
- JsonUriDataContract.cs
- FieldNameLookup.cs
- TrackingRecord.cs
- SeparatorAutomationPeer.cs
- propertyentry.cs
- ParseNumbers.cs
- IdentityManager.cs
- SingleObjectCollection.cs
- BitVector32.cs
- RepeaterItem.cs
- DataSourceSelectArguments.cs
- DrawingVisualDrawingContext.cs
- SymmetricAlgorithm.cs
- WebMessageEncodingBindingElement.cs
- FormViewDeletedEventArgs.cs
- Assert.cs
- HostingEnvironment.cs
- TypeDescriptor.cs
- QueryableFilterUserControl.cs
- FixedSOMPageElement.cs
- XPathNode.cs