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
- DbExpressionRules.cs
- LoadedOrUnloadedOperation.cs
- CustomAttributeFormatException.cs
- CodeSnippetStatement.cs
- AssertFilter.cs
- GroupBox.cs
- QueryableDataSourceHelper.cs
- XmlSchemaAnnotation.cs
- _NetworkingPerfCounters.cs
- ArrayWithOffset.cs
- Filter.cs
- Hex.cs
- Help.cs
- XPathAncestorQuery.cs
- storepermissionattribute.cs
- Stylus.cs
- AuthenticateEventArgs.cs
- HideDisabledControlAdapter.cs
- SynchronizedChannelCollection.cs
- TextCharacters.cs
- EventBuilder.cs
- CorrelationKey.cs
- DescendantQuery.cs
- ReadOnlyCollection.cs
- SequenceDesigner.cs
- ProfileSection.cs
- InstancePersistenceCommandException.cs
- CompilerTypeWithParams.cs
- XPathNodeHelper.cs
- DataListItemCollection.cs
- SiteIdentityPermission.cs
- Trace.cs
- DefinitionUpdate.cs
- WebMessageFormatHelper.cs
- ToolStripSplitStackLayout.cs
- DecoderFallbackWithFailureFlag.cs
- SortFieldComparer.cs
- SectionUpdates.cs
- ParentQuery.cs
- ContractValidationHelper.cs
- DataMember.cs
- MailSettingsSection.cs
- EntityDescriptor.cs
- WrapperSecurityCommunicationObject.cs
- NativeMethodsOther.cs
- EntityDataSourceContextDisposingEventArgs.cs
- UpdateCompiler.cs
- InvariantComparer.cs
- SafeSecurityHandles.cs
- AssociationSetMetadata.cs
- BinHexDecoder.cs
- HierarchicalDataBoundControlAdapter.cs
- TemplateField.cs
- OutOfProcStateClientManager.cs
- SqlGatherProducedAliases.cs
- ExtentKey.cs
- SQLConvert.cs
- Trigger.cs
- LocalizationParserHooks.cs
- RepeaterDataBoundAdapter.cs
- EventWaitHandleSecurity.cs
- WebPartPersonalization.cs
- PackageDigitalSignatureManager.cs
- ProviderIncompatibleException.cs
- DbParameterCollection.cs
- InheritedPropertyChangedEventArgs.cs
- InvalidOleVariantTypeException.cs
- DataGridViewCellMouseEventArgs.cs
- SessionSwitchEventArgs.cs
- PreProcessor.cs
- ProcessHostFactoryHelper.cs
- FixedTextSelectionProcessor.cs
- Style.cs
- ProcessModelSection.cs
- InputBindingCollection.cs
- ToolStripSplitButton.cs
- FontCollection.cs
- ChtmlCommandAdapter.cs
- TableChangeProcessor.cs
- CodeRegionDirective.cs
- Keywords.cs
- Array.cs
- ListDictionary.cs
- DateTimeConverter2.cs
- ListViewInsertedEventArgs.cs
- XmlAttributeCollection.cs
- ToolStripContentPanel.cs
- ConfigXmlReader.cs
- FamilyCollection.cs
- WindowVisualStateTracker.cs
- ApplicationFileParser.cs
- ProtocolViolationException.cs
- StickyNoteAnnotations.cs
- GradientStopCollection.cs
- DataSourceHelper.cs
- ActionMismatchAddressingException.cs
- KeyPressEvent.cs
- ButtonDesigner.cs
- BufferedGraphicsContext.cs
- AuthenticateEventArgs.cs