Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- GuidelineCollection.cs
- ProfileGroupSettingsCollection.cs
- GeneratedCodeAttribute.cs
- FixedTextView.cs
- DataGridViewElement.cs
- SelectionHighlightInfo.cs
- HyperLink.cs
- ExpandableObjectConverter.cs
- ConnectorDragDropGlyph.cs
- EntitySqlQueryState.cs
- ShapeTypeface.cs
- ClientSession.cs
- DropTarget.cs
- AuthorizationSection.cs
- TokenBasedSetEnumerator.cs
- RectangleHotSpot.cs
- BaseResourcesBuildProvider.cs
- MarginsConverter.cs
- IOException.cs
- AttachedPropertyBrowsableWhenAttributePresentAttribute.cs
- ButtonAutomationPeer.cs
- HtmlSelect.cs
- PropertyManager.cs
- DiscoveryDocumentReference.cs
- HierarchicalDataBoundControl.cs
- SingleObjectCollection.cs
- SerializationInfo.cs
- SqlPersistenceProviderFactory.cs
- ContractDescription.cs
- SizeAnimationClockResource.cs
- HeaderedItemsControl.cs
- BrowserInteropHelper.cs
- Pens.cs
- ICollection.cs
- ButtonBaseAutomationPeer.cs
- SafeReadContext.cs
- LinkTarget.cs
- WebRequestModuleElementCollection.cs
- CLSCompliantAttribute.cs
- AssemblySettingAttributes.cs
- MessageBox.cs
- ImageMapEventArgs.cs
- StaticSiteMapProvider.cs
- ContractHandle.cs
- ServiceThrottlingElement.cs
- DocumentPageView.cs
- UnicodeEncoding.cs
- DataServiceProcessingPipeline.cs
- AudioException.cs
- UpDownBase.cs
- XmlSchemaGroup.cs
- QilXmlWriter.cs
- LinkArea.cs
- CharacterMetrics.cs
- TypeFieldSchema.cs
- ConsoleKeyInfo.cs
- CharacterMetrics.cs
- Rect.cs
- SQLByte.cs
- ModifierKeysConverter.cs
- DropDownButton.cs
- SiteMapPathDesigner.cs
- WebPartCatalogCloseVerb.cs
- EventMappingSettings.cs
- UniqueIdentifierService.cs
- TakeQueryOptionExpression.cs
- Signature.cs
- PageRanges.cs
- DetailsViewPageEventArgs.cs
- DateTime.cs
- ListViewUpdateEventArgs.cs
- ApplicationBuildProvider.cs
- HttpTransportBindingElement.cs
- SerializationSectionGroup.cs
- NamespaceDisplayAutomationPeer.cs
- FixedSOMFixedBlock.cs
- EdmToObjectNamespaceMap.cs
- BitmapEffectDrawingContextWalker.cs
- ProjectionPruner.cs
- SiteMapDataSourceDesigner.cs
- util.cs
- SQLMoney.cs
- TypeDescriptionProvider.cs
- DataSourceConverter.cs
- SoapExtension.cs
- AncillaryOps.cs
- SmiRequestExecutor.cs
- PostBackOptions.cs
- FormParameter.cs
- TypeDescriptor.cs
- CommandManager.cs
- ListParaClient.cs
- DefaultAuthorizationContext.cs
- complextypematerializer.cs
- WindowsListViewGroup.cs
- ScriptControl.cs
- PublisherMembershipCondition.cs
- VolatileEnlistmentState.cs
- ButtonChrome.cs
- BulletDecorator.cs