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
- ContextMenuService.cs
- WebPartVerbCollection.cs
- Tracking.cs
- SqlNotificationRequest.cs
- XmlDocumentType.cs
- XmlObjectSerializer.cs
- SplineKeyFrames.cs
- cookie.cs
- LookupNode.cs
- RegistrationServices.cs
- DesignerActionPropertyItem.cs
- IntSecurity.cs
- WindowInteropHelper.cs
- CipherData.cs
- ReflectionUtil.cs
- BindingElement.cs
- ColumnMapVisitor.cs
- DATA_BLOB.cs
- XmlHelper.cs
- ResourceExpressionBuilder.cs
- Dictionary.cs
- GPRECT.cs
- AccessDataSource.cs
- TracedNativeMethods.cs
- DataGridCommandEventArgs.cs
- CalendarDay.cs
- DecoderFallback.cs
- HttpRuntimeSection.cs
- ChtmlTextWriter.cs
- RelationshipDetailsCollection.cs
- SplineKeyFrames.cs
- VirtualPath.cs
- SessionPageStateSection.cs
- ConfigXmlAttribute.cs
- HtmlInputText.cs
- ImageKeyConverter.cs
- Icon.cs
- TextTreeFixupNode.cs
- HttpCookieCollection.cs
- _DisconnectOverlappedAsyncResult.cs
- CodeStatement.cs
- SelectionPattern.cs
- MissingMemberException.cs
- HttpConfigurationContext.cs
- PerspectiveCamera.cs
- XmlSchemaComplexContentExtension.cs
- DataGridViewCellValueEventArgs.cs
- XmlNullResolver.cs
- DataProtection.cs
- RegistryConfigurationProvider.cs
- DataException.cs
- SecurityHeaderTokenResolver.cs
- TableLayout.cs
- ParallelTimeline.cs
- WindowsToolbarItemAsMenuItem.cs
- TableLayoutColumnStyleCollection.cs
- HebrewNumber.cs
- Propagator.Evaluator.cs
- _BufferOffsetSize.cs
- CLSCompliantAttribute.cs
- StylusPointProperties.cs
- MarshalDirectiveException.cs
- SqlDataAdapter.cs
- SharedDp.cs
- SubMenuStyle.cs
- SimpleBitVector32.cs
- SpoolingTaskBase.cs
- ProgressBar.cs
- LabelAutomationPeer.cs
- ActivityInstance.cs
- Soap.cs
- ReceiveContextCollection.cs
- Simplifier.cs
- OrderedHashRepartitionStream.cs
- Style.cs
- SamlSecurityTokenAuthenticator.cs
- OrderByQueryOptionExpression.cs
- DataViewManagerListItemTypeDescriptor.cs
- DataSourceXmlClassAttribute.cs
- RecordBuilder.cs
- Trigger.cs
- CultureInfoConverter.cs
- FormatterServices.cs
- HtmlToClrEventProxy.cs
- QueryExtender.cs
- hebrewshape.cs
- StateDesigner.Layouts.cs
- WebEvents.cs
- DbQueryCommandTree.cs
- PolyLineSegment.cs
- BaseValidator.cs
- XmlChildEnumerator.cs
- OracleInfoMessageEventArgs.cs
- CommandLibraryHelper.cs
- DataServiceConfiguration.cs
- ProxyFragment.cs
- PaintEvent.cs
- KeyBinding.cs
- XmlException.cs
- HttpRequestTraceRecord.cs