Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- ClosableStream.cs
- SimpleApplicationHost.cs
- SessionStateContainer.cs
- ObjectDataSourceChooseMethodsPanel.cs
- NamespaceQuery.cs
- ScriptServiceAttribute.cs
- SelectionRange.cs
- FieldTemplateFactory.cs
- PrintPageEvent.cs
- UInt64Storage.cs
- TextElementEditingBehaviorAttribute.cs
- CaseCqlBlock.cs
- CompositeTypefaceMetrics.cs
- Span.cs
- CodeDelegateCreateExpression.cs
- Rect.cs
- BitmapImage.cs
- Emitter.cs
- AutoResizedEvent.cs
- login.cs
- Propagator.cs
- SessionPageStateSection.cs
- CircleHotSpot.cs
- EncryptedPackageFilter.cs
- ClusterSafeNativeMethods.cs
- DataSourceProvider.cs
- ColumnWidthChangingEvent.cs
- SqlBinder.cs
- ScrollViewer.cs
- RegexCompilationInfo.cs
- PartitionResolver.cs
- SamlConditions.cs
- EdmPropertyAttribute.cs
- WebPartHelpVerb.cs
- CuspData.cs
- TextSelectionProcessor.cs
- Executor.cs
- ToolStripPanel.cs
- MaskedTextProvider.cs
- SmiContext.cs
- SiteMap.cs
- WCFModelStrings.Designer.cs
- FunctionOverloadResolver.cs
- SessionPageStateSection.cs
- _CommandStream.cs
- MethodRental.cs
- EntryIndex.cs
- XmlNamedNodeMap.cs
- XmlSchemaAttributeGroupRef.cs
- StringArrayConverter.cs
- SizeConverter.cs
- FileEnumerator.cs
- DiscoveryMessageSequence11.cs
- TdsEnums.cs
- WebChannelFactory.cs
- ValuePattern.cs
- Transform3D.cs
- SmiEventSink.cs
- RoleService.cs
- ExpandSegment.cs
- ListViewDesigner.cs
- ContractMapping.cs
- DataObjectFieldAttribute.cs
- ReferenceSchema.cs
- EmulateRecognizeCompletedEventArgs.cs
- ITreeGenerator.cs
- XPathBinder.cs
- SettingsPropertyNotFoundException.cs
- SecurityHeaderTokenResolver.cs
- GenerateTemporaryAssemblyTask.cs
- LinkedList.cs
- KeyNotFoundException.cs
- KeyValueConfigurationCollection.cs
- SymmetricAlgorithm.cs
- DisplayClaim.cs
- WebControlsSection.cs
- ElementProxy.cs
- ComboBox.cs
- ModuleBuilder.cs
- PaginationProgressEventArgs.cs
- TextDecorations.cs
- OleDbMetaDataFactory.cs
- ContainerUIElement3D.cs
- Library.cs
- Crc32Helper.cs
- ConfigurationSectionCollection.cs
- BuildResult.cs
- _Semaphore.cs
- TreeView.cs
- VisualProxy.cs
- SyndicationContent.cs
- TextPatternIdentifiers.cs
- UnsafeNetInfoNativeMethods.cs
- NativeMethods.cs
- CombinedGeometry.cs
- SoapIgnoreAttribute.cs
- ApplicationTrust.cs
- ControlPropertyNameConverter.cs
- SerializationFieldInfo.cs
- DataServiceHostFactory.cs