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
- XmlElementList.cs
- VisualBasicValue.cs
- SqlUdtInfo.cs
- ConnectionPoolManager.cs
- NavigationPropertyEmitter.cs
- PatternMatcher.cs
- Accessible.cs
- UserInitiatedNavigationPermission.cs
- XmlBoundElement.cs
- PeerCollaborationPermission.cs
- DataView.cs
- Transform.cs
- UnionExpr.cs
- DoubleStorage.cs
- webproxy.cs
- ClipboardData.cs
- FormViewAutoFormat.cs
- Vars.cs
- LocalizationComments.cs
- SQLMembershipProvider.cs
- DbConnectionStringCommon.cs
- HierarchicalDataSourceDesigner.cs
- UrlPropertyAttribute.cs
- Set.cs
- CategoriesDocumentFormatter.cs
- SelectionProcessor.cs
- FixedFlowMap.cs
- PeerNameRecordCollection.cs
- UnsupportedPolicyOptionsException.cs
- DictionaryGlobals.cs
- LoadGrammarCompletedEventArgs.cs
- RoutedEvent.cs
- SqlNode.cs
- LocalBuilder.cs
- AuthenticatingEventArgs.cs
- TemplatePropertyEntry.cs
- SystemMulticastIPAddressInformation.cs
- TextPointer.cs
- ContentValidator.cs
- HandlerFactoryCache.cs
- DefaultValueAttribute.cs
- WebControlAdapter.cs
- DependencyProperty.cs
- XmlAnyElementAttributes.cs
- TrackingServices.cs
- EntryWrittenEventArgs.cs
- ElementAction.cs
- FilterableAttribute.cs
- HtmlTextBoxAdapter.cs
- Timer.cs
- TypeSystemHelpers.cs
- LinqDataSourceUpdateEventArgs.cs
- FixedSOMFixedBlock.cs
- InkSerializer.cs
- PageCanvasSize.cs
- LinkedList.cs
- StringArrayConverter.cs
- Single.cs
- ObjectListFieldCollection.cs
- NotifyIcon.cs
- WebPartConnectionsCloseVerb.cs
- EventLogReader.cs
- ErrorFormatter.cs
- EventLogSession.cs
- StreamUpgradeInitiator.cs
- UserControl.cs
- LinkedList.cs
- HwndSourceKeyboardInputSite.cs
- Rules.cs
- XmlResolver.cs
- BitVector32.cs
- SqlGenericUtil.cs
- EventMappingSettings.cs
- FrameworkContentElementAutomationPeer.cs
- VisualTreeUtils.cs
- SqlRemoveConstantOrderBy.cs
- LineInfo.cs
- SqlDuplicator.cs
- ByteAnimationUsingKeyFrames.cs
- BatchServiceHost.cs
- GifBitmapEncoder.cs
- ExpressionBindings.cs
- PeerMaintainer.cs
- EntityTypeBase.cs
- OleDbCommandBuilder.cs
- GifBitmapEncoder.cs
- HtmlInputRadioButton.cs
- Cast.cs
- FocusWithinProperty.cs
- EventEntry.cs
- TextDecoration.cs
- KernelTypeValidation.cs
- TimeSpanStorage.cs
- NonParentingControl.cs
- ObjectSecurity.cs
- XmlAttributes.cs
- FixedDocument.cs
- DbDataReader.cs
- _TransmitFileOverlappedAsyncResult.cs
- XPathScanner.cs