Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- CategoryAttribute.cs
- SmiGettersStream.cs
- CounterCreationDataCollection.cs
- Column.cs
- SafeSecurityHelper.cs
- CodeIdentifiers.cs
- TemplateField.cs
- PreviewPrintController.cs
- _SSPISessionCache.cs
- LinkedResourceCollection.cs
- MissingFieldException.cs
- Base64Encoder.cs
- XmlUtil.cs
- SchemaType.cs
- TypedTableGenerator.cs
- Metadata.cs
- PipeStream.cs
- TypedTableHandler.cs
- cookiecontainer.cs
- compensatingcollection.cs
- EventSetter.cs
- HostProtectionPermission.cs
- SqlTypesSchemaImporter.cs
- SslStreamSecurityElement.cs
- XmlSchemaSimpleTypeRestriction.cs
- SoapReflectionImporter.cs
- ColumnTypeConverter.cs
- TableLayoutRowStyleCollection.cs
- CheckPair.cs
- PropertyDescriptor.cs
- InvalidProgramException.cs
- ThousandthOfEmRealPoints.cs
- CodeDOMProvider.cs
- SimpleWorkerRequest.cs
- ExtractedStateEntry.cs
- PartialCachingAttribute.cs
- CodeValidator.cs
- TableRow.cs
- DockEditor.cs
- BackStopAuthenticationModule.cs
- FilterQueryOptionExpression.cs
- GridViewSelectEventArgs.cs
- ManualResetEvent.cs
- CurrentChangingEventManager.cs
- SecurityPermission.cs
- FullTextState.cs
- VariantWrapper.cs
- Listbox.cs
- ConstructorBuilder.cs
- GradientStopCollection.cs
- TextPattern.cs
- NavigationHelper.cs
- WriteTimeStream.cs
- TraceSwitch.cs
- MD5CryptoServiceProvider.cs
- XsdDataContractImporter.cs
- ProxySimple.cs
- StructuralObject.cs
- XmlNavigatorFilter.cs
- LassoSelectionBehavior.cs
- ListViewGroup.cs
- MatrixKeyFrameCollection.cs
- FormatterConverter.cs
- SoapInteropTypes.cs
- GeneralTransform.cs
- LinkedResourceCollection.cs
- NativeMethods.cs
- StringUtil.cs
- PeerContact.cs
- RoleManagerModule.cs
- XmlFormatExtensionPointAttribute.cs
- ListViewContainer.cs
- DataGridCommandEventArgs.cs
- IsolatedStoragePermission.cs
- EmptyReadOnlyDictionaryInternal.cs
- CodePageEncoding.cs
- TextTreeTextBlock.cs
- XmlSchemaElement.cs
- CompositeDataBoundControl.cs
- PerformanceCounterLib.cs
- NamedElement.cs
- TemplateKey.cs
- Calendar.cs
- TextMarkerSource.cs
- Baml2006KnownTypes.cs
- __Error.cs
- CodeCatchClause.cs
- SerialStream.cs
- TrackBarRenderer.cs
- MenuEventArgs.cs
- UpdateManifestForBrowserApplication.cs
- TextRangeSerialization.cs
- DockPanel.cs
- ContextStaticAttribute.cs
- EFTableProvider.cs
- LogicalExpr.cs
- RootBrowserWindow.cs
- DataGridTablesFactory.cs
- FrugalMap.cs
- XmlSerializerSection.cs