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
- BitmapSource.cs
- SchemaElementLookUpTableEnumerator.cs
- DataSourceHelper.cs
- DateTimeOffsetStorage.cs
- cryptoapiTransform.cs
- WorkflowElementDialog.cs
- VideoDrawing.cs
- AdvancedBindingEditor.cs
- NetworkInformationPermission.cs
- EventSinkHelperWriter.cs
- XPathException.cs
- XmlExtensionFunction.cs
- SharedPerformanceCounter.cs
- FormViewUpdateEventArgs.cs
- InputProcessorProfilesLoader.cs
- WhitespaceSignificantCollectionAttribute.cs
- RubberbandSelector.cs
- LinearGradientBrush.cs
- NullableLongSumAggregationOperator.cs
- Light.cs
- XmlArrayItemAttributes.cs
- LoginUtil.cs
- SimpleWorkerRequest.cs
- ConfigurationSectionGroup.cs
- CapabilitiesRule.cs
- StdRegProviderWrapper.cs
- RegexStringValidatorAttribute.cs
- DirectoryObjectSecurity.cs
- CharacterHit.cs
- WebInvokeAttribute.cs
- LayoutTableCell.cs
- SafeNativeMethods.cs
- _FtpControlStream.cs
- ElementProxy.cs
- IgnoreFileBuildProvider.cs
- EntityClientCacheKey.cs
- IndentTextWriter.cs
- OleDbException.cs
- PieceNameHelper.cs
- HtmlInputHidden.cs
- OutputCacheModule.cs
- WebPartsSection.cs
- DataGridRowAutomationPeer.cs
- DefaultTextStore.cs
- HttpWebRequestElement.cs
- ComponentDispatcherThread.cs
- ConfigurationManagerHelper.cs
- CompilerLocalReference.cs
- EnvironmentPermission.cs
- GeneratedCodeAttribute.cs
- Simplifier.cs
- MD5.cs
- Bind.cs
- serverconfig.cs
- EntityProxyTypeInfo.cs
- AlternateViewCollection.cs
- DropSource.cs
- SliderAutomationPeer.cs
- ToolStripRenderer.cs
- PropertyPathConverter.cs
- OracleMonthSpan.cs
- ResourceContainer.cs
- MetadataCollection.cs
- TraceUtility.cs
- ImageMapEventArgs.cs
- TextFormatterImp.cs
- NativeRightsManagementAPIsStructures.cs
- ManualResetEvent.cs
- Package.cs
- HttpTransportSecurity.cs
- CodePropertyReferenceExpression.cs
- ImageField.cs
- BinaryObjectReader.cs
- DNS.cs
- HTMLTagNameToTypeMapper.cs
- InvalidCastException.cs
- ControlType.cs
- XmlMapping.cs
- xmlglyphRunInfo.cs
- BufferedGraphicsManager.cs
- VariableBinder.cs
- RoutedEventValueSerializer.cs
- ParseHttpDate.cs
- SelectedDatesCollection.cs
- ServicePoint.cs
- UserNameServiceElement.cs
- GridViewRowPresenterBase.cs
- TrackingMemoryStream.cs
- XamlReader.cs
- StandardBindingCollectionElement.cs
- TriggerAction.cs
- ZipIOExtraField.cs
- ConstrainedDataObject.cs
- CapabilitiesUse.cs
- DialogResultConverter.cs
- CollectionBuilder.cs
- IUnknownConstantAttribute.cs
- storepermission.cs
- StrokeNodeOperations.cs
- ToolStripItemGlyph.cs