Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- xmlglyphRunInfo.cs
- DataGridBoolColumn.cs
- SymbolDocumentInfo.cs
- ServiceBusyException.cs
- Token.cs
- QueryStoreStatusRequest.cs
- InlinedAggregationOperatorEnumerator.cs
- FrameworkRichTextComposition.cs
- GregorianCalendarHelper.cs
- TemplateGroupCollection.cs
- DataBoundControlParameterTarget.cs
- WebCategoryAttribute.cs
- CurrencyManager.cs
- SqlTrackingWorkflowInstance.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- SqlWorkflowPersistenceService.cs
- SmiRequestExecutor.cs
- CustomLineCap.cs
- AssociatedControlConverter.cs
- SystemWebExtensionsSectionGroup.cs
- Size3DConverter.cs
- RsaSecurityTokenAuthenticator.cs
- XmlNodeReader.cs
- ServicePrincipalNameElement.cs
- SqlClientWrapperSmiStreamChars.cs
- RootBrowserWindowProxy.cs
- AnchorEditor.cs
- IDReferencePropertyAttribute.cs
- DesignerAdRotatorAdapter.cs
- Scene3D.cs
- MsmqIntegrationChannelListener.cs
- BorderGapMaskConverter.cs
- ServicePointManager.cs
- DateTimeFormatInfo.cs
- MetadataCacheItem.cs
- Calendar.cs
- MouseActionValueSerializer.cs
- Emitter.cs
- BrowsableAttribute.cs
- __TransparentProxy.cs
- LiteralLink.cs
- TraceContextEventArgs.cs
- ValidatorAttribute.cs
- Literal.cs
- PrinterSettings.cs
- CallbackValidatorAttribute.cs
- MembershipSection.cs
- RangeValuePattern.cs
- FormViewInsertedEventArgs.cs
- InfoCardArgumentException.cs
- DictionaryChange.cs
- WindowsTitleBar.cs
- SerialPinChanges.cs
- VisualTransition.cs
- FilterableAttribute.cs
- FormsAuthenticationTicket.cs
- GridView.cs
- IDispatchConstantAttribute.cs
- ProtocolsConfigurationEntry.cs
- ItemCollection.cs
- cookieexception.cs
- FormsAuthenticationCredentials.cs
- DbDataRecord.cs
- WindowsStartMenu.cs
- PathTooLongException.cs
- HtmlControlPersistable.cs
- SqlConnection.cs
- SecUtil.cs
- TypedTableGenerator.cs
- DataGridViewTextBoxCell.cs
- ExceptionUtil.cs
- TextAdaptor.cs
- ProfileParameter.cs
- Int64Converter.cs
- StorageComplexTypeMapping.cs
- EntryPointNotFoundException.cs
- StringResourceManager.cs
- ComplexBindingPropertiesAttribute.cs
- CodeLabeledStatement.cs
- ConfigurationSectionCollection.cs
- Baml2006SchemaContext.cs
- MediaElement.cs
- XamlFilter.cs
- HttpClientChannel.cs
- Hex.cs
- ValidationSummary.cs
- XmlStringTable.cs
- EventItfInfo.cs
- TdsParser.cs
- PriorityBinding.cs
- OpCopier.cs
- DataFieldConverter.cs
- OpenTypeLayout.cs
- ListBoxItem.cs
- TimelineCollection.cs
- MeshGeometry3D.cs
- EmbossBitmapEffect.cs
- SoapHttpTransportImporter.cs
- FileDataSourceCache.cs
- ChineseLunisolarCalendar.cs