Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Tools / WSATConfig / Configuration / SafeLocalAllocation.cs / 1305376 / SafeLocalAllocation.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace Microsoft.Tools.ServiceModel.WsatConfig { using System; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using Microsoft.Win32.SafeHandles; sealed class SafeLocalAllocation : SafeHandleZeroOrMinusOneIsInvalid { [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] internal SafeLocalAllocation(int size) : base(true) { #pragma warning suppress 56523 IntPtr pointer = SafeNativeMethods.LocalAlloc(SafeNativeMethods.LMEM_ZEROINIT, size); SetHandle(pointer); } #if WSAT_UI [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] internal SafeLocalAllocation(object source) : base(true) { #pragma warning suppress 56523 IntPtr pointer = SafeNativeMethods.LocalAlloc(SafeNativeMethods.LMEM_ZEROINIT, Marshal.SizeOf(source)); SetHandle(pointer); Marshal.StructureToPtr( source, handle, false); } #endif internal void Copy(byte[] source, int startIndex, int count) { System.Runtime.InteropServices.Marshal.Copy( source, startIndex, handle, count); } protected override bool ReleaseHandle() { #pragma warning suppress 56523 IntPtr r = SafeNativeMethods.LocalFree(handle); return r == IntPtr.Zero; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace Microsoft.Tools.ServiceModel.WsatConfig { using System; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using Microsoft.Win32.SafeHandles; sealed class SafeLocalAllocation : SafeHandleZeroOrMinusOneIsInvalid { [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] internal SafeLocalAllocation(int size) : base(true) { #pragma warning suppress 56523 IntPtr pointer = SafeNativeMethods.LocalAlloc(SafeNativeMethods.LMEM_ZEROINIT, size); SetHandle(pointer); } #if WSAT_UI [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] internal SafeLocalAllocation(object source) : base(true) { #pragma warning suppress 56523 IntPtr pointer = SafeNativeMethods.LocalAlloc(SafeNativeMethods.LMEM_ZEROINIT, Marshal.SizeOf(source)); SetHandle(pointer); Marshal.StructureToPtr( source, handle, false); } #endif internal void Copy(byte[] source, int startIndex, int count) { System.Runtime.InteropServices.Marshal.Copy( source, startIndex, handle, count); } protected override bool ReleaseHandle() { #pragma warning suppress 56523 IntPtr r = SafeNativeMethods.LocalFree(handle); return r == IntPtr.Zero; } } } // 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
- IncrementalReadDecoders.cs
- XamlVector3DCollectionSerializer.cs
- OneOf.cs
- ListViewAutomationPeer.cs
- InputLanguageProfileNotifySink.cs
- WebMessageBodyStyleHelper.cs
- EntityDataSourceReferenceGroup.cs
- ParentQuery.cs
- XmlSchemaDocumentation.cs
- X509Utils.cs
- Substitution.cs
- LayoutSettings.cs
- TableStyle.cs
- SpecularMaterial.cs
- COM2ColorConverter.cs
- DataGridViewColumn.cs
- Color.cs
- ThaiBuddhistCalendar.cs
- TableItemPatternIdentifiers.cs
- FocusTracker.cs
- RemoteWebConfigurationHost.cs
- LinqDataSource.cs
- Component.cs
- ButtonFieldBase.cs
- XslCompiledTransform.cs
- PrintPageEvent.cs
- MD5.cs
- OutputCacheProfile.cs
- ExpressionBindings.cs
- VirtualDirectoryMappingCollection.cs
- DetailsView.cs
- OdbcDataReader.cs
- BitVector32.cs
- DataGridViewCellLinkedList.cs
- ButtonStandardAdapter.cs
- XdrBuilder.cs
- BuildResultCache.cs
- PropertyEmitter.cs
- Stack.cs
- EntityWithChangeTrackerStrategy.cs
- FileSecurity.cs
- JumpList.cs
- Pts.cs
- GridViewRowEventArgs.cs
- HasCopySemanticsAttribute.cs
- HttpRequest.cs
- PropertyChangedEventArgs.cs
- WebRequestModulesSection.cs
- CheckPair.cs
- AnnotationAuthorChangedEventArgs.cs
- FontNamesConverter.cs
- DataServiceHost.cs
- ItemList.cs
- ServicesSection.cs
- DataListItemEventArgs.cs
- IPPacketInformation.cs
- OwnerDrawPropertyBag.cs
- ThicknessConverter.cs
- Hex.cs
- Int64Storage.cs
- IndexedString.cs
- PerformanceCounter.cs
- ContainerAction.cs
- ProfileProvider.cs
- TaskResultSetter.cs
- NullableLongSumAggregationOperator.cs
- WindowsTreeView.cs
- SystemEvents.cs
- RequestCacheEntry.cs
- SessionStateItemCollection.cs
- CodeCompiler.cs
- MultiPageTextView.cs
- TextLine.cs
- SimplePropertyEntry.cs
- tooltip.cs
- SimpleHandlerFactory.cs
- XsdCachingReader.cs
- DataGridTableCollection.cs
- Int64Converter.cs
- OleDbParameter.cs
- BStrWrapper.cs
- ElementNotEnabledException.cs
- TextRangeBase.cs
- HttpResponseHeader.cs
- BulletedListEventArgs.cs
- IndexOutOfRangeException.cs
- ConfigurationSectionCollection.cs
- PersonalizationStateQuery.cs
- DbProviderManifest.cs
- RuleProcessor.cs
- SqlProviderManifest.cs
- ExpressionBuilder.cs
- GenericTypeParameterConverter.cs
- DetailsViewUpdateEventArgs.cs
- AdjustableArrowCap.cs
- ContentType.cs
- PermissionSet.cs
- ShaderEffect.cs
- DynamicActivityProperty.cs
- OletxCommittableTransaction.cs