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
- querybuilder.cs
- TemplatedWizardStep.cs
- BlobPersonalizationState.cs
- Row.cs
- CatalogZoneAutoFormat.cs
- ProcessHostConfigUtils.cs
- PrinterUnitConvert.cs
- RangeValueProviderWrapper.cs
- JsonGlobals.cs
- KeyValuePair.cs
- DocumentSchemaValidator.cs
- ByteStorage.cs
- BasicViewGenerator.cs
- ConfigurationSettings.cs
- FunctionDetailsReader.cs
- WorkflowInstance.cs
- LayoutInformation.cs
- BooleanSwitch.cs
- UseManagedPresentationBindingElement.cs
- RegistrySecurity.cs
- DynamicDiscoSearcher.cs
- ManagedIStream.cs
- AlgoModule.cs
- KeyedQueue.cs
- SystemIPGlobalStatistics.cs
- ReflectionTypeLoadException.cs
- ExpressionEditorAttribute.cs
- QuadraticBezierSegment.cs
- BitmapFrameDecode.cs
- FileIOPermission.cs
- VisualTarget.cs
- BitmapData.cs
- Int16AnimationUsingKeyFrames.cs
- GenerateTemporaryAssemblyTask.cs
- WaitHandleCannotBeOpenedException.cs
- validation.cs
- DecimalConstantAttribute.cs
- thaishape.cs
- HandlerFactoryCache.cs
- BitmapSourceSafeMILHandle.cs
- ExtenderControl.cs
- MatchingStyle.cs
- TraceHandlerErrorFormatter.cs
- NumberAction.cs
- StrokeNode.cs
- XPathNavigator.cs
- DependencyObject.cs
- safelinkcollection.cs
- DataObjectPastingEventArgs.cs
- NetMsmqBinding.cs
- TrackingServices.cs
- DiagnosticsConfiguration.cs
- StatusBarPanelClickEvent.cs
- DurationConverter.cs
- GridProviderWrapper.cs
- HttpRuntimeSection.cs
- TaskFileService.cs
- ReadOnlyDictionary.cs
- diagnosticsswitches.cs
- TypeHelpers.cs
- MetadataCacheItem.cs
- BaseResourcesBuildProvider.cs
- SimpleApplicationHost.cs
- DependencyProperty.cs
- ExecutionTracker.cs
- ObjectViewFactory.cs
- _BaseOverlappedAsyncResult.cs
- FrameworkEventSource.cs
- IndependentAnimationStorage.cs
- SystemIcmpV6Statistics.cs
- ProfileProvider.cs
- VectorConverter.cs
- WorkItem.cs
- ColorTransform.cs
- TextRange.cs
- ConfigXmlElement.cs
- ToolboxItemImageConverter.cs
- InfoCardAsymmetricCrypto.cs
- TreeBuilderBamlTranslator.cs
- AnnotationService.cs
- DataObjectSettingDataEventArgs.cs
- EventArgs.cs
- WinEventHandler.cs
- ControlIdConverter.cs
- WebDisplayNameAttribute.cs
- GradientBrush.cs
- IISUnsafeMethods.cs
- CanonicalXml.cs
- PolicyException.cs
- PropertyGrid.cs
- OutputCacheSection.cs
- XsdValidatingReader.cs
- FixedSOMGroup.cs
- PeerPresenceInfo.cs
- odbcmetadatafactory.cs
- TraceListeners.cs
- RenderTargetBitmap.cs
- KernelTypeValidation.cs
- CodeCompiler.cs
- WebServiceClientProxyGenerator.cs