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
- InputScopeNameConverter.cs
- InfoCardTraceRecord.cs
- Figure.cs
- TraceEventCache.cs
- ProfileService.cs
- LazyTextWriterCreator.cs
- ExitEventArgs.cs
- RightsManagementManager.cs
- DelegatedStream.cs
- CachedFontFace.cs
- OleDbError.cs
- PackageFilter.cs
- TdsRecordBufferSetter.cs
- DispatcherOperation.cs
- ColumnHeader.cs
- Font.cs
- XdrBuilder.cs
- BigInt.cs
- ManifestResourceInfo.cs
- RequiredAttributeAttribute.cs
- xmlfixedPageInfo.cs
- keycontainerpermission.cs
- OpCopier.cs
- RegexGroup.cs
- ConnectorDragDropGlyph.cs
- ProxyWebPartConnectionCollection.cs
- ConnectionStringsExpressionEditor.cs
- LinkConverter.cs
- SqlNodeAnnotations.cs
- AffineTransform3D.cs
- WebServiceClientProxyGenerator.cs
- ExternalException.cs
- CodeTypeOfExpression.cs
- XmlDocument.cs
- ScrollProperties.cs
- SourceChangedEventArgs.cs
- CTreeGenerator.cs
- XmlSchemaObjectTable.cs
- LogLogRecordHeader.cs
- SqlStream.cs
- AuthenticatingEventArgs.cs
- WebPartTracker.cs
- DependencyObject.cs
- XsdCachingReader.cs
- SyndicationDeserializer.cs
- DataBindingExpressionBuilder.cs
- SecurityTokenParameters.cs
- XmlSchemaException.cs
- NamespaceList.cs
- BuildProvidersCompiler.cs
- ConstraintStruct.cs
- Container.cs
- ProcessRequestArgs.cs
- Formatter.cs
- CodeGen.cs
- RegexCompilationInfo.cs
- Int32CAMarshaler.cs
- TreeChangeInfo.cs
- DateTimePicker.cs
- Point.cs
- SimplePropertyEntry.cs
- XmlSignatureManifest.cs
- ImageCodecInfoPrivate.cs
- GAC.cs
- RecipientIdentity.cs
- ValueOfAction.cs
- ObjectMemberMapping.cs
- CopyAttributesAction.cs
- securestring.cs
- CipherData.cs
- HasCopySemanticsAttribute.cs
- WebPartEditVerb.cs
- ManifestBasedResourceGroveler.cs
- HashHelpers.cs
- DbProviderServices.cs
- Regex.cs
- AutomationProperties.cs
- EncoderReplacementFallback.cs
- BindingElementCollection.cs
- XmlCDATASection.cs
- DataFormats.cs
- BasePattern.cs
- DummyDataSource.cs
- Application.cs
- LinqDataSourceUpdateEventArgs.cs
- MiniModule.cs
- ObjectStateFormatter.cs
- HtmlInputHidden.cs
- GridViewUpdatedEventArgs.cs
- DownloadProgressEventArgs.cs
- RuntimeResourceSet.cs
- x509store.cs
- UIAgentMonitor.cs
- VariantWrapper.cs
- EventLog.cs
- ReadOnlyHierarchicalDataSourceView.cs
- CounterSample.cs
- CheckBox.cs
- ComponentEditorForm.cs
- ScrollChangedEventArgs.cs