Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / UIAutomation / Win32Providers / MS / Internal / AutomationProxies / SafeCoTaskMem.cs / 1305600 / 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
- __ComObject.cs
- MimeFormatter.cs
- PagedDataSource.cs
- Model3D.cs
- ContainerControl.cs
- Socket.cs
- assertwrapper.cs
- AvTrace.cs
- AnchorEditor.cs
- Button.cs
- ToolStripItemClickedEventArgs.cs
- XamlStackWriter.cs
- BufferedOutputStream.cs
- DataControlCommands.cs
- EncryptedPackageFilter.cs
- DescendentsWalker.cs
- Math.cs
- Comparer.cs
- EventDriven.cs
- ImportCatalogPart.cs
- MobileListItemCollection.cs
- EmptyEnumerable.cs
- IxmlLineInfo.cs
- RemoteWebConfigurationHost.cs
- GridSplitter.cs
- IntSecurity.cs
- XPathAxisIterator.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- HelpProvider.cs
- StringUtil.cs
- RequestSecurityTokenResponse.cs
- GlyphingCache.cs
- PassportIdentity.cs
- FontEmbeddingManager.cs
- DynamicHyperLink.cs
- FieldNameLookup.cs
- EncryptedPackage.cs
- TemplateModeChangedEventArgs.cs
- HostExecutionContextManager.cs
- CompensationHandlingFilter.cs
- BaseParagraph.cs
- IItemProperties.cs
- SQLDateTime.cs
- ConstructorArgumentAttribute.cs
- IndexingContentUnit.cs
- ActivityTypeResolver.xaml.cs
- RenderData.cs
- PackageDigitalSignatureManager.cs
- CompModSwitches.cs
- MaterialGroup.cs
- StyleHelper.cs
- InputScopeNameConverter.cs
- XmlSchemaSimpleContent.cs
- LayoutSettings.cs
- MsmqInputMessage.cs
- TypedElement.cs
- lengthconverter.cs
- ParserExtension.cs
- SmtpFailedRecipientsException.cs
- Code.cs
- Vector3DAnimationUsingKeyFrames.cs
- SiteMapSection.cs
- SkewTransform.cs
- LongValidatorAttribute.cs
- RSAOAEPKeyExchangeFormatter.cs
- ObjectQueryProvider.cs
- XmlNamedNodeMap.cs
- EventToken.cs
- HttpGetClientProtocol.cs
- _emptywebproxy.cs
- ArgumentValueSerializer.cs
- ClientSession.cs
- Roles.cs
- PathGeometry.cs
- LocalFileSettingsProvider.cs
- LockCookie.cs
- MasterPage.cs
- Point3D.cs
- StrokeIntersection.cs
- BaseDataBoundControl.cs
- ServiceOperationUIEditor.cs
- OpacityConverter.cs
- InvokeHandlers.cs
- SafeNativeMethods.cs
- XmlReflectionImporter.cs
- ValuePattern.cs
- BinaryCommonClasses.cs
- HttpCookieCollection.cs
- CriticalExceptions.cs
- ScrollBar.cs
- ResourceSetExpression.cs
- FixUp.cs
- DataSourceCacheDurationConverter.cs
- StylusTip.cs
- Formatter.cs
- JoinGraph.cs
- SingleSelectRootGridEntry.cs
- ProcessProtocolHandler.cs
- WindowsRichEdit.cs
- OrderByQueryOptionExpression.cs