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
- AppSettingsExpressionBuilder.cs
- CopyOnWriteList.cs
- _NegoState.cs
- DataGridItemEventArgs.cs
- DoubleAnimationUsingKeyFrames.cs
- HttpConfigurationContext.cs
- RadioButtonAutomationPeer.cs
- DbDeleteCommandTree.cs
- BaseCodeDomTreeGenerator.cs
- SetStoryboardSpeedRatio.cs
- Padding.cs
- Point3D.cs
- PrinterResolution.cs
- BaseValidator.cs
- OracleCommand.cs
- TableLayoutPanel.cs
- IdentityReference.cs
- BatchStream.cs
- TypeValidationEventArgs.cs
- CodeDomComponentSerializationService.cs
- ButtonChrome.cs
- GridViewCommandEventArgs.cs
- assertwrapper.cs
- DescendentsWalkerBase.cs
- Matrix3DStack.cs
- DataGridTable.cs
- UniformGrid.cs
- StreamInfo.cs
- CheckPair.cs
- SQLGuidStorage.cs
- ProgressiveCrcCalculatingStream.cs
- MimeXmlReflector.cs
- SqlBulkCopy.cs
- TrustSection.cs
- EventData.cs
- SendKeys.cs
- PolicyUnit.cs
- ContractMapping.cs
- SortedList.cs
- CommandField.cs
- LinkTarget.cs
- CellLabel.cs
- CustomValidator.cs
- LinqToSqlWrapper.cs
- SubqueryTrackingVisitor.cs
- PromptBuilder.cs
- MexTcpBindingElement.cs
- TraceListener.cs
- XomlCompilerParameters.cs
- ParagraphVisual.cs
- XPathNode.cs
- precedingquery.cs
- ConvertBinder.cs
- TraceContextRecord.cs
- XmlSerializerVersionAttribute.cs
- OleDbErrorCollection.cs
- SmtpClient.cs
- TrackBarRenderer.cs
- ToolboxDataAttribute.cs
- ExceptionHandlers.cs
- SlipBehavior.cs
- RegexTree.cs
- ImageKeyConverter.cs
- CroppedBitmap.cs
- DbTransaction.cs
- VirtualizedCellInfoCollection.cs
- DataKeyCollection.cs
- EventMemberCodeDomSerializer.cs
- MonitoringDescriptionAttribute.cs
- StringResourceManager.cs
- DBPropSet.cs
- Section.cs
- Transform3D.cs
- DiscardableAttribute.cs
- WindowsSolidBrush.cs
- MailWriter.cs
- CodeAccessSecurityEngine.cs
- Math.cs
- ExtendLockAsyncResult.cs
- SQLBoolean.cs
- QueryConverter.cs
- DataGridState.cs
- VisualTreeHelper.cs
- XmlStringTable.cs
- CTreeGenerator.cs
- PersistenceProvider.cs
- KerberosSecurityTokenAuthenticator.cs
- TextDecorationCollection.cs
- UserPreference.cs
- SerializationObjectManager.cs
- Switch.cs
- IsolatedStorageFileStream.cs
- FixedDocument.cs
- MultipartContentParser.cs
- Relationship.cs
- ToolStripDropDown.cs
- IPEndPoint.cs
- TableHeaderCell.cs
- XmlException.cs
- xmlsaver.cs