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
- elementinformation.cs
- ShapingWorkspace.cs
- HttpNamespaceReservationInstallComponent.cs
- CheckBoxDesigner.cs
- QueryStringConverter.cs
- Internal.cs
- URLString.cs
- DoubleLinkListEnumerator.cs
- ProviderCommandInfoUtils.cs
- HtmlGenericControl.cs
- UrlPropertyAttribute.cs
- TableChangeProcessor.cs
- EditingCommands.cs
- SecurityException.cs
- TreeView.cs
- ColorInterpolationModeValidation.cs
- DataGridTextBoxColumn.cs
- XmlSchemaObjectTable.cs
- QuaternionKeyFrameCollection.cs
- PeerApplication.cs
- CompositeCollection.cs
- InternalRelationshipCollection.cs
- FileDialogCustomPlaces.cs
- XsltArgumentList.cs
- MouseGestureConverter.cs
- SimpleHandlerFactory.cs
- BitmapPalettes.cs
- CroppedBitmap.cs
- ProjectionPath.cs
- ProfilePropertySettings.cs
- UrlAuthFailedErrorFormatter.cs
- MarshalByValueComponent.cs
- LinqDataSourceContextEventArgs.cs
- NamespaceCollection.cs
- ConfigurationException.cs
- dataobject.cs
- TextBoxBase.cs
- storagemappingitemcollection.viewdictionary.cs
- ReferencedType.cs
- TrackingProfileCache.cs
- sqlstateclientmanager.cs
- Pipe.cs
- HtmlAnchor.cs
- PageThemeParser.cs
- Tile.cs
- BasicSecurityProfileVersion.cs
- FastEncoderWindow.cs
- RichTextBoxAutomationPeer.cs
- UserControlCodeDomTreeGenerator.cs
- DBDataPermissionAttribute.cs
- HttpResponseHeader.cs
- ElapsedEventArgs.cs
- SerializableTypeCodeDomSerializer.cs
- DebugHandleTracker.cs
- ImageSource.cs
- SiteIdentityPermission.cs
- SqlFlattener.cs
- SslStream.cs
- Compilation.cs
- JavaScriptString.cs
- Utils.cs
- BindingNavigatorDesigner.cs
- GuidelineSet.cs
- LineMetrics.cs
- TabControl.cs
- DocumentViewerBaseAutomationPeer.cs
- DesignOnlyAttribute.cs
- ToolConsole.cs
- OrderByBuilder.cs
- FileVersionInfo.cs
- CodeAttributeDeclarationCollection.cs
- QueryParameter.cs
- ListDataHelper.cs
- XmlSchemaInclude.cs
- ContextMenu.cs
- ImageDrawing.cs
- ToolStripDropDownButton.cs
- MouseGestureConverter.cs
- MissingMemberException.cs
- DataBindingExpressionBuilder.cs
- MetadataUtil.cs
- ControlCachePolicy.cs
- MessageQueuePermissionEntryCollection.cs
- securestring.cs
- CatalogPartCollection.cs
- BuilderInfo.cs
- EndpointAddressMessageFilter.cs
- EditorAttributeInfo.cs
- TypeInitializationException.cs
- BamlResourceSerializer.cs
- WrapPanel.cs
- Vector3DValueSerializer.cs
- COMException.cs
- XmlSchemaObject.cs
- MeasurementDCInfo.cs
- BitmapSourceSafeMILHandle.cs
- BoundsDrawingContextWalker.cs
- returneventsaver.cs
- Size.cs
- PerformanceCountersElement.cs