Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / UIAutomation / Win32Providers / MS / Internal / AutomationProxies / SafeCoTaskMem.cs / 1 / SafeCoTaskMem.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // // History: // 10/04/2003 : [....] Created //--------------------------------------------------------------------------- using System; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; using MS.Win32; namespace MS.Internal.AutomationProxies { internal sealed class SafeCoTaskMem : SafeHandleZeroOrMinusOneIsInvalid { // This constructor is used by the P/Invoke marshaling layer // to allocate a SafeHandle instance. P/Invoke then does the // appropriate method call, storing the handle in this class. private SafeCoTaskMem() : base(true) {} internal SafeCoTaskMem(int length) : base(true) { SetHandle(Marshal.AllocCoTaskMem(length * sizeof (char))); } internal string GetStringAuto() { return Marshal.PtrToStringAuto(handle); } internal string GetStringUni(int length) { // Convert the local unmanaged buffer in to a string object return Marshal.PtrToStringUni(handle, length); } // protected override bool ReleaseHandle() { Marshal.FreeCoTaskMem(handle); return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // // History: // 10/04/2003 : [....] Created //--------------------------------------------------------------------------- using System; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; using MS.Win32; namespace MS.Internal.AutomationProxies { internal sealed class SafeCoTaskMem : SafeHandleZeroOrMinusOneIsInvalid { // This constructor is used by the P/Invoke marshaling layer // to allocate a SafeHandle instance. P/Invoke then does the // appropriate method call, storing the handle in this class. private SafeCoTaskMem() : base(true) {} internal SafeCoTaskMem(int length) : base(true) { SetHandle(Marshal.AllocCoTaskMem(length * sizeof (char))); } internal string GetStringAuto() { return Marshal.PtrToStringAuto(handle); } internal string GetStringUni(int length) { // Convert the local unmanaged buffer in to a string object return Marshal.PtrToStringUni(handle, length); } // protected override bool ReleaseHandle() { Marshal.FreeCoTaskMem(handle); return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RequestCachePolicy.cs
- AssemblyCacheEntry.cs
- FocusManager.cs
- CTreeGenerator.cs
- XmlCDATASection.cs
- ListDataHelper.cs
- MaterialGroup.cs
- TextTrailingCharacterEllipsis.cs
- ReadOnlyTernaryTree.cs
- X509ChainPolicy.cs
- ConfigXmlComment.cs
- DBCSCodePageEncoding.cs
- QueryCacheKey.cs
- ClientScriptManagerWrapper.cs
- AttributeData.cs
- ExpressionBuilderContext.cs
- codemethodreferenceexpression.cs
- SafeBitVector32.cs
- LinkConverter.cs
- WebBaseEventKeyComparer.cs
- PointKeyFrameCollection.cs
- ObjectConverter.cs
- SystemNetworkInterface.cs
- PlacementWorkspace.cs
- VBCodeProvider.cs
- ClientApiGenerator.cs
- GradientPanel.cs
- Vector3DKeyFrameCollection.cs
- MatrixIndependentAnimationStorage.cs
- SchemaTypeEmitter.cs
- MaterializeFromAtom.cs
- QueueProcessor.cs
- HyperLinkColumn.cs
- MessageBox.cs
- SqlNodeTypeOperators.cs
- AssemblyCollection.cs
- HostingMessageProperty.cs
- XPathNavigator.cs
- RowBinding.cs
- ObjectStateFormatter.cs
- NamespaceEmitter.cs
- HMACMD5.cs
- ManifestResourceInfo.cs
- ListControlDesigner.cs
- SetIterators.cs
- TdsParserHelperClasses.cs
- SqlDataSourceFilteringEventArgs.cs
- DataListItem.cs
- Contracts.cs
- RootBrowserWindowProxy.cs
- XPathAncestorIterator.cs
- Control.cs
- EditorPartCollection.cs
- ErrorCodes.cs
- TransformDescriptor.cs
- Events.cs
- GenerateTemporaryTargetAssembly.cs
- GenericsNotImplementedException.cs
- MissingSatelliteAssemblyException.cs
- DataControlImageButton.cs
- OdbcTransaction.cs
- CodeTypeReferenceCollection.cs
- GridItemCollection.cs
- DataGridViewCellValueEventArgs.cs
- WebBrowserUriTypeConverter.cs
- ColumnClickEvent.cs
- CodeEntryPointMethod.cs
- ListBox.cs
- Image.cs
- ServerType.cs
- StoragePropertyMapping.cs
- ResourceDescriptionAttribute.cs
- FigureHelper.cs
- PropertyGeneratedEventArgs.cs
- DelegateBodyWriter.cs
- _CookieModule.cs
- Trace.cs
- ProfileGroupSettings.cs
- XsdDataContractExporter.cs
- MILUtilities.cs
- MappingSource.cs
- DbConnectionFactory.cs
- HashAlgorithm.cs
- FileDetails.cs
- ListChangedEventArgs.cs
- StorageAssociationTypeMapping.cs
- OleDbConnection.cs
- PagesChangedEventArgs.cs
- XmlSchemaFacet.cs
- IisTraceWebEventProvider.cs
- NativeMethods.cs
- XmlNamedNodeMap.cs
- ManipulationLogic.cs
- VectorValueSerializer.cs
- TcpClientChannel.cs
- OpenTypeLayoutCache.cs
- NavigationPropertyEmitter.cs
- RegexParser.cs
- M3DUtil.cs
- BaseTemplateCodeDomTreeGenerator.cs