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
- WebPartEditVerb.cs
- DeflateStreamAsyncResult.cs
- ModelChangedEventArgsImpl.cs
- assemblycache.cs
- ScriptManagerProxy.cs
- PaintEvent.cs
- WSSecurityOneDotOneReceiveSecurityHeader.cs
- TemplateNameScope.cs
- DataGridViewCellEventArgs.cs
- XmlWriterSettings.cs
- ReadOnlyActivityGlyph.cs
- BamlTreeNode.cs
- PrintControllerWithStatusDialog.cs
- RectConverter.cs
- AssociationEndMember.cs
- ComponentResourceManager.cs
- Label.cs
- SchemaLookupTable.cs
- TextBreakpoint.cs
- StreamSecurityUpgradeProvider.cs
- WebControlsSection.cs
- WebSysDisplayNameAttribute.cs
- HotSpot.cs
- SoapClientProtocol.cs
- Perspective.cs
- XPathDocumentIterator.cs
- ProtocolElement.cs
- PartialTrustValidationBehavior.cs
- NewExpression.cs
- ToolboxDataAttribute.cs
- GridItem.cs
- WebContentFormatHelper.cs
- CorrelationManager.cs
- TextSpanModifier.cs
- WindowShowOrOpenTracker.cs
- MemoryRecordBuffer.cs
- WindowsStatic.cs
- TreeIterators.cs
- LabelAutomationPeer.cs
- StreamWithDictionary.cs
- Monitor.cs
- FromReply.cs
- SHA1Managed.cs
- TimersDescriptionAttribute.cs
- RequiredAttributeAttribute.cs
- Metafile.cs
- LoadItemsEventArgs.cs
- ParameterToken.cs
- WebPartUtil.cs
- NominalTypeEliminator.cs
- SamlAdvice.cs
- ImageClickEventArgs.cs
- ButtonStandardAdapter.cs
- DataSourceSelectArguments.cs
- LayoutTable.cs
- HtmlGenericControl.cs
- _FtpControlStream.cs
- UniqueIdentifierService.cs
- ListViewInsertedEventArgs.cs
- New.cs
- HMAC.cs
- GetTokenRequest.cs
- _RequestLifetimeSetter.cs
- AppliedDeviceFiltersDialog.cs
- FileDataSource.cs
- XomlCompilerHelpers.cs
- DateTimeEditor.cs
- EncryptedData.cs
- RegexCaptureCollection.cs
- Binding.cs
- ResourceLoader.cs
- ProcessHostMapPath.cs
- XPathConvert.cs
- DataKeyArray.cs
- PackUriHelper.cs
- StringPropertyBuilder.cs
- NetCodeGroup.cs
- GridViewRowPresenter.cs
- TypeLibConverter.cs
- __TransparentProxy.cs
- CompositeClientFormatter.cs
- EdmRelationshipRoleAttribute.cs
- StringUtil.cs
- DocumentOrderQuery.cs
- RegexCode.cs
- AccessDataSource.cs
- WmiInstallComponent.cs
- TempEnvironment.cs
- SelectedDatesCollection.cs
- DrawListViewColumnHeaderEventArgs.cs
- SoapException.cs
- OrderByBuilder.cs
- _IPv4Address.cs
- PrivateUnsafeNativeCompoundFileMethods.cs
- CultureInfoConverter.cs
- DateTimeConstantAttribute.cs
- FloaterParagraph.cs
- ValueUtilsSmi.cs
- IERequestCache.cs
- XmlObjectSerializer.cs