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
- EncodingStreamWrapper.cs
- TreeNodeCollection.cs
- InternalCache.cs
- DetailsViewModeEventArgs.cs
- SqlParameter.cs
- itemelement.cs
- ProcessProtocolHandler.cs
- BamlReader.cs
- WebPartCatalogCloseVerb.cs
- Path.cs
- DataTransferEventArgs.cs
- httpserverutility.cs
- _LocalDataStoreMgr.cs
- MsmqProcessProtocolHandler.cs
- TreeNodeBindingCollection.cs
- EntityClassGenerator.cs
- BamlRecordWriter.cs
- WebConfigurationManager.cs
- SchemaManager.cs
- DataRowChangeEvent.cs
- Int32Rect.cs
- MetadataArtifactLoader.cs
- Win32PrintDialog.cs
- XmlHelper.cs
- XmlDataDocument.cs
- DefaultSection.cs
- LogicalMethodInfo.cs
- Base64Encoder.cs
- ComponentManagerBroker.cs
- CanonicalFormWriter.cs
- x509store.cs
- SqlDataRecord.cs
- GridLength.cs
- SettingsSection.cs
- SqlXmlStorage.cs
- XmlSerializationReader.cs
- CanExecuteRoutedEventArgs.cs
- PeerCollaboration.cs
- CompilerCollection.cs
- SqlClientWrapperSmiStreamChars.cs
- bindurihelper.cs
- AsyncDataRequest.cs
- StandardOleMarshalObject.cs
- MouseButton.cs
- EntityObject.cs
- TypeDescriptorContext.cs
- Timer.cs
- NoneExcludedImageIndexConverter.cs
- DocumentPageHost.cs
- TimelineGroup.cs
- Group.cs
- SelectionChangedEventArgs.cs
- SelectionWordBreaker.cs
- TriggerCollection.cs
- TextProperties.cs
- TextTreeNode.cs
- ListViewSortEventArgs.cs
- ComPlusDiagnosticTraceSchemas.cs
- CalloutQueueItem.cs
- LinqExpressionNormalizer.cs
- ImageButton.cs
- DecoderNLS.cs
- ColorTranslator.cs
- CompressionTracing.cs
- Memoizer.cs
- SQLCharsStorage.cs
- SqlTriggerContext.cs
- TypefaceMap.cs
- BaseServiceProvider.cs
- CodeTypeReferenceExpression.cs
- AuthenticationSection.cs
- BamlBinaryReader.cs
- UriTemplateCompoundPathSegment.cs
- LeafCellTreeNode.cs
- MenuRenderer.cs
- FixedTextBuilder.cs
- OutputCacheProfileCollection.cs
- peernodeimplementation.cs
- GPRECT.cs
- ChangePassword.cs
- RuleRefElement.cs
- CodeMethodInvokeExpression.cs
- PropertiesTab.cs
- AbstractDataSvcMapFileLoader.cs
- FileDialogCustomPlace.cs
- CqlWriter.cs
- ValidationRuleCollection.cs
- TableRow.cs
- DisplayInformation.cs
- ListenerTraceUtility.cs
- AdPostCacheSubstitution.cs
- DataServiceExpressionVisitor.cs
- Empty.cs
- XmlNavigatorFilter.cs
- infer.cs
- DisableDpiAwarenessAttribute.cs
- SqlTypeConverter.cs
- RectIndependentAnimationStorage.cs
- PersonalizationState.cs
- ChannelParameterCollection.cs