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
- UIntPtr.cs
- CheckableControlBaseAdapter.cs
- HwndHostAutomationPeer.cs
- DynamicResourceExtensionConverter.cs
- XPathDocumentNavigator.cs
- DataPointer.cs
- SqlDataSourceEnumerator.cs
- XmlSchemaSet.cs
- Utility.cs
- FormDesigner.cs
- OdbcError.cs
- TimeManager.cs
- XmlSyndicationContent.cs
- RpcCryptoRequest.cs
- PeerApplication.cs
- HtmlInputCheckBox.cs
- tibetanshape.cs
- HtmlInputImage.cs
- ConnectionProviderAttribute.cs
- WizardStepCollectionEditor.cs
- RectValueSerializer.cs
- XPathSingletonIterator.cs
- DataSourceNameHandler.cs
- SerializationStore.cs
- NativeMethods.cs
- DataTransferEventArgs.cs
- AnimationLayer.cs
- BehaviorEditorPart.cs
- DocumentPageTextView.cs
- ToolStripRenderer.cs
- isolationinterop.cs
- ImageInfo.cs
- PrivateFontCollection.cs
- TypeConstant.cs
- DataAdapter.cs
- Errors.cs
- ZipIOLocalFileHeader.cs
- FrameSecurityDescriptor.cs
- BamlLocalizer.cs
- VirtualDirectoryMapping.cs
- HttpDigestClientCredential.cs
- ModifierKeysValueSerializer.cs
- GACMembershipCondition.cs
- WebEventTraceProvider.cs
- TypedElement.cs
- CheckBoxFlatAdapter.cs
- SchemaCollectionCompiler.cs
- CodeBinaryOperatorExpression.cs
- PassportIdentity.cs
- SqlAggregateChecker.cs
- UriParserTemplates.cs
- RecipientInfo.cs
- ForeignKeyConstraint.cs
- MessageContractMemberAttribute.cs
- Command.cs
- ToolboxItemAttribute.cs
- ZeroOpNode.cs
- WindowsUpDown.cs
- LinkedDataMemberFieldEditor.cs
- SqlTypeSystemProvider.cs
- HtmlTableRow.cs
- MetaModel.cs
- CalculatedColumn.cs
- FlowPosition.cs
- TextServicesCompartment.cs
- PermissionSet.cs
- SoapIgnoreAttribute.cs
- ContextMenuService.cs
- TextEffectResolver.cs
- EFDataModelProvider.cs
- InputLangChangeEvent.cs
- SmiRequestExecutor.cs
- OdbcErrorCollection.cs
- LifetimeServices.cs
- PropertyToken.cs
- OrderedDictionaryStateHelper.cs
- WebPartZoneBase.cs
- BlockCollection.cs
- Journaling.cs
- CreateUserErrorEventArgs.cs
- ModulesEntry.cs
- FontCacheUtil.cs
- ScrollEventArgs.cs
- DockingAttribute.cs
- ReliableMessagingHelpers.cs
- DispatchWrapper.cs
- GridView.cs
- FixedSOMSemanticBox.cs
- SizeAnimationClockResource.cs
- NullRuntimeConfig.cs
- HotSpot.cs
- AuthenticationModuleElement.cs
- BitmapEffectInput.cs
- WorkflowViewManager.cs
- HwndSourceParameters.cs
- MetaTable.cs
- XmlSchemaImport.cs
- RightsManagementEncryptedStream.cs
- LinqDataView.cs
- RuntimeVariableList.cs