Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StatusBarDrawItemEvent.cs
- ResourceSet.cs
- TablePattern.cs
- GacUtil.cs
- NativeRightsManagementAPIsStructures.cs
- FaultDesigner.cs
- TextCompositionEventArgs.cs
- TableParaClient.cs
- RegexCompilationInfo.cs
- FrameworkElement.cs
- Menu.cs
- XmlElement.cs
- FieldBuilder.cs
- AssemblyBuilder.cs
- DatagridviewDisplayedBandsData.cs
- SizeAnimation.cs
- Int64.cs
- SetIterators.cs
- TypefaceCollection.cs
- StagingAreaInputItem.cs
- WebScriptMetadataFormatter.cs
- AutomationPropertyInfo.cs
- AnnotationObservableCollection.cs
- Visual.cs
- Imaging.cs
- ListenerAdapter.cs
- XPathExpr.cs
- PnrpPermission.cs
- WebServiceErrorEvent.cs
- ProcessHost.cs
- HtmlMeta.cs
- SessionMode.cs
- DotNetATv1WindowsLogEntryDeserializer.cs
- FieldTemplateUserControl.cs
- BamlBinaryWriter.cs
- SystemInfo.cs
- Calendar.cs
- PrePrepareMethodAttribute.cs
- AVElementHelper.cs
- RequestSecurityTokenResponseCollection.cs
- ReachDocumentReferenceCollectionSerializerAsync.cs
- DataListItemCollection.cs
- ProxySimple.cs
- RectIndependentAnimationStorage.cs
- UInt16.cs
- SafeProcessHandle.cs
- StringFreezingAttribute.cs
- MergeLocalizationDirectives.cs
- Group.cs
- ScrollableControl.cs
- ReceiveActivityDesigner.cs
- BamlBinaryReader.cs
- Region.cs
- Line.cs
- WmlPanelAdapter.cs
- LiteralTextContainerControlBuilder.cs
- OrderedDictionary.cs
- ZoneButton.cs
- WebSysDescriptionAttribute.cs
- XmlUtf8RawTextWriter.cs
- NativeActivityContext.cs
- DataServiceEntityAttribute.cs
- MouseBinding.cs
- ElementFactory.cs
- SchemaImporterExtensionsSection.cs
- SmtpFailedRecipientException.cs
- DetailsViewModeEventArgs.cs
- HMACSHA256.cs
- TabControlDesigner.cs
- RegistrationServices.cs
- DesignBindingValueUIHandler.cs
- Style.cs
- SystemWebCachingSectionGroup.cs
- ReachSerializableProperties.cs
- HtmlUtf8RawTextWriter.cs
- WebPartMenuStyle.cs
- FileChangesMonitor.cs
- TypeInfo.cs
- MailHeaderInfo.cs
- EventPropertyMap.cs
- AmbientLight.cs
- XsdBuildProvider.cs
- ProfileProvider.cs
- CharStorage.cs
- ReadWriteObjectLock.cs
- DataTrigger.cs
- DoubleAverageAggregationOperator.cs
- IndexedEnumerable.cs
- HelloMessage11.cs
- PropertyCollection.cs
- Number.cs
- ExternalCalls.cs
- ControlDesigner.cs
- IsolatedStorage.cs
- CompareValidator.cs
- ActivityDesigner.cs
- ConvertEvent.cs
- DataListItemCollection.cs
- TypeSemantics.cs
- XmlReflectionMember.cs