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
- BlockExpression.cs
- ListChangedEventArgs.cs
- DescendantQuery.cs
- ListView.cs
- HttpProxyCredentialType.cs
- OutputCacheSettings.cs
- CheckoutException.cs
- LostFocusEventManager.cs
- ReadOnlyDictionary.cs
- ScriptControlDescriptor.cs
- ColorComboBox.cs
- AssemblySettingAttributes.cs
- HttpRequest.cs
- HandlerBase.cs
- DataControlField.cs
- DaylightTime.cs
- DBProviderConfigurationHandler.cs
- LabelLiteral.cs
- FormatSettings.cs
- XmlIgnoreAttribute.cs
- ObjectAssociationEndMapping.cs
- SemaphoreSecurity.cs
- DataPagerField.cs
- PropertyReferenceSerializer.cs
- NumberFormatInfo.cs
- SystemUnicastIPAddressInformation.cs
- NamedPipeTransportSecurity.cs
- XmlChildNodes.cs
- NativeActivityContext.cs
- UInt64Converter.cs
- TypographyProperties.cs
- RsaKeyIdentifierClause.cs
- sitestring.cs
- HotCommands.cs
- FileResponseElement.cs
- TranslateTransform3D.cs
- WebPartConnectionsConfigureVerb.cs
- TextClipboardData.cs
- ParallelRangeManager.cs
- TextElement.cs
- ProvidersHelper.cs
- PartDesigner.cs
- AnonymousIdentificationSection.cs
- securitycriticaldataClass.cs
- ToRequest.cs
- ping.cs
- ErrorRuntimeConfig.cs
- DoubleLinkListEnumerator.cs
- OrderedDictionary.cs
- QilChoice.cs
- X509PeerCertificateAuthentication.cs
- DynamicPropertyHolder.cs
- CodeDirectoryCompiler.cs
- DefaultTextStore.cs
- PersistChildrenAttribute.cs
- ProjectionCamera.cs
- Thickness.cs
- TransformCollection.cs
- OdbcRowUpdatingEvent.cs
- SelectedGridItemChangedEvent.cs
- InstanceData.cs
- DataGridViewRowEventArgs.cs
- Point.cs
- PlainXmlDeserializer.cs
- Serialization.cs
- TableRowGroupCollection.cs
- HyperLinkStyle.cs
- OAVariantLib.cs
- ChtmlPageAdapter.cs
- DataViewManagerListItemTypeDescriptor.cs
- FlowLayout.cs
- InkCanvasSelectionAdorner.cs
- TrustManagerPromptUI.cs
- DispatcherSynchronizationContext.cs
- LayoutTable.cs
- LeftCellWrapper.cs
- XmlIlGenerator.cs
- WS2007FederationHttpBindingElement.cs
- EncoderFallback.cs
- NamespaceTable.cs
- HandlerMappingMemo.cs
- StrongNamePublicKeyBlob.cs
- ApplicationProxyInternal.cs
- CultureSpecificStringDictionary.cs
- DataChangedEventManager.cs
- _NestedSingleAsyncResult.cs
- CheckBoxStandardAdapter.cs
- TemplatedMailWebEventProvider.cs
- WmlObjectListAdapter.cs
- MediaTimeline.cs
- GeometryHitTestResult.cs
- WebBrowsableAttribute.cs
- TdsRecordBufferSetter.cs
- FacetEnabledSchemaElement.cs
- PersonalizationState.cs
- DecimalStorage.cs
- ExtensionQuery.cs
- Vector.cs
- DeferredElementTreeState.cs
- HyperLink.cs