Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- DataObject.cs
- RelationshipManager.cs
- ConfigUtil.cs
- AppDomainFactory.cs
- PartialList.cs
- ActionFrame.cs
- _AutoWebProxyScriptWrapper.cs
- FixedSOMPageConstructor.cs
- XmlILModule.cs
- WebPartHelpVerb.cs
- Schema.cs
- XsdSchemaFileEditor.cs
- GPPOINT.cs
- BrowserDefinitionCollection.cs
- SmtpClient.cs
- DataGridViewImageColumn.cs
- DataColumnChangeEvent.cs
- SqlError.cs
- MasterPage.cs
- TypeUtil.cs
- DataView.cs
- documentsequencetextcontainer.cs
- DispatcherHookEventArgs.cs
- WindowsRichEdit.cs
- ProfileSettingsCollection.cs
- ClaimTypes.cs
- ComplexTypeEmitter.cs
- DelegateSerializationHolder.cs
- HttpDictionary.cs
- wpf-etw.cs
- Rule.cs
- BooleanExpr.cs
- TemplateControlBuildProvider.cs
- Solver.cs
- GridViewColumnCollection.cs
- DSASignatureDeformatter.cs
- DataGridColumnReorderingEventArgs.cs
- Utilities.cs
- TreeNodeStyleCollectionEditor.cs
- XmlMembersMapping.cs
- Matrix3DValueSerializer.cs
- NameHandler.cs
- SQLBytes.cs
- WorkflowTimerService.cs
- DictionaryGlobals.cs
- XmlIlTypeHelper.cs
- COM2EnumConverter.cs
- WindowsAuthenticationEventArgs.cs
- InvalidAsynchronousStateException.cs
- UnmanagedMemoryStreamWrapper.cs
- AuthenticationServiceManager.cs
- ProfessionalColors.cs
- QuerySelectOp.cs
- ConfigXmlSignificantWhitespace.cs
- FormatterConverter.cs
- Size.cs
- EventListener.cs
- CachedPathData.cs
- InvalidContentTypeException.cs
- CreateUserWizard.cs
- IOThreadTimer.cs
- SinglePhaseEnlistment.cs
- SurrogateDataContract.cs
- ContractReference.cs
- ControlPropertyNameConverter.cs
- ProcessingInstructionAction.cs
- WebResponse.cs
- DataControlButton.cs
- RealProxy.cs
- CachedTypeface.cs
- __ConsoleStream.cs
- TrackingProfileCache.cs
- TypeContext.cs
- MaskedTextBoxDesignerActionList.cs
- Identity.cs
- SystemFonts.cs
- TextPenaltyModule.cs
- DateTimeFormatInfoScanner.cs
- LinkTarget.cs
- AddressAccessDeniedException.cs
- DNS.cs
- ManagementClass.cs
- DefaultProxySection.cs
- Utils.cs
- ReturnType.cs
- SqlDataSourceStatusEventArgs.cs
- HttpListenerRequestUriBuilder.cs
- ComboBox.cs
- DataListItem.cs
- RadioButtonPopupAdapter.cs
- DateTimeOffsetAdapter.cs
- Win32Exception.cs
- DisplayMemberTemplateSelector.cs
- PropertyMapper.cs
- Rfc2898DeriveBytes.cs
- BitmapCodecInfo.cs
- ClassicBorderDecorator.cs
- HtmlTable.cs
- BuiltInPermissionSets.cs
- SelectedDatesCollection.cs