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
- WebPartDisplayModeCancelEventArgs.cs
- WebPartManagerInternals.cs
- PartialCachingControl.cs
- CopyNamespacesAction.cs
- PermissionSetEnumerator.cs
- LocalizableResourceBuilder.cs
- AdPostCacheSubstitution.cs
- ClassDataContract.cs
- OverflowException.cs
- WebBrowserPermission.cs
- RequestBringIntoViewEventArgs.cs
- TreeNodeEventArgs.cs
- RenderContext.cs
- LineGeometry.cs
- Soap.cs
- MimeBasePart.cs
- TableCellAutomationPeer.cs
- HttpCapabilitiesSectionHandler.cs
- SqlRowUpdatedEvent.cs
- ToolStripSettings.cs
- DataGridViewUtilities.cs
- QilReplaceVisitor.cs
- Globals.cs
- EventHandlers.cs
- ObjectHandle.cs
- PlainXmlWriter.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- BaseParagraph.cs
- UniqueEventHelper.cs
- DataGridAddNewRow.cs
- CollectionViewSource.cs
- EntityDescriptor.cs
- VoiceChangeEventArgs.cs
- Privilege.cs
- FacetValueContainer.cs
- Transform3DGroup.cs
- MouseGesture.cs
- SecondaryIndex.cs
- Stylus.cs
- MergeFilterQuery.cs
- XmlQueryTypeFactory.cs
- TreeNodeConverter.cs
- StringCollection.cs
- ReadonlyMessageFilter.cs
- embossbitmapeffect.cs
- LassoHelper.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- _Semaphore.cs
- BinHexDecoder.cs
- OdbcConnectionString.cs
- TextViewSelectionProcessor.cs
- AppLevelCompilationSectionCache.cs
- StorageEndPropertyMapping.cs
- XmlSchemaSimpleType.cs
- BamlCollectionHolder.cs
- DataGridViewCellLinkedList.cs
- WpfWebRequestHelper.cs
- DataControlFieldCell.cs
- BinaryConverter.cs
- ResourcesGenerator.cs
- CriticalFinalizerObject.cs
- DefaultTextStoreTextComposition.cs
- ManifestResourceInfo.cs
- BinaryObjectReader.cs
- TrackingServices.cs
- PtsPage.cs
- SessionEndingCancelEventArgs.cs
- TagPrefixCollection.cs
- HtmlInputText.cs
- TypeLibConverter.cs
- SemaphoreFullException.cs
- Transform3D.cs
- DataRowChangeEvent.cs
- COM2ExtendedTypeConverter.cs
- LabelLiteral.cs
- DeviceFilterDictionary.cs
- DesignerCatalogPartChrome.cs
- TraceContextRecord.cs
- UnauthorizedWebPart.cs
- CqlWriter.cs
- ConfigurationElementProperty.cs
- GroupBoxAutomationPeer.cs
- EmptyReadOnlyDictionaryInternal.cs
- PackagePartCollection.cs
- WebPartTransformerCollection.cs
- EnumConverter.cs
- UnsafeNativeMethods.cs
- FontSourceCollection.cs
- AncestorChangedEventArgs.cs
- ToolZoneDesigner.cs
- AuthenticateEventArgs.cs
- Matrix.cs
- WebPartConnectionsCancelEventArgs.cs
- EasingKeyFrames.cs
- Deflater.cs
- ErrorHandler.cs
- PersonalizationProvider.cs
- TextRange.cs
- BackStopAuthenticationModule.cs
- EntityCommandDefinition.cs