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
- MultiView.cs
- MenuAdapter.cs
- OledbConnectionStringbuilder.cs
- SqlBuilder.cs
- SchemaMapping.cs
- SQLResource.cs
- MarshalDirectiveException.cs
- WebPartActionVerb.cs
- CoreSwitches.cs
- AudioStateChangedEventArgs.cs
- UniqueCodeIdentifierScope.cs
- CustomAttributeSerializer.cs
- DataContractAttribute.cs
- MenuAutomationPeer.cs
- _Connection.cs
- DataGridViewComboBoxColumn.cs
- ToolStripDropDownClosedEventArgs.cs
- CacheMemory.cs
- BrowserCapabilitiesCompiler.cs
- _Events.cs
- CompilerState.cs
- DataGridViewComboBoxCell.cs
- HighContrastHelper.cs
- InstanceHandleConflictException.cs
- EditingCommands.cs
- DotExpr.cs
- DataTableNewRowEvent.cs
- XmlDataProvider.cs
- DateTimeValueSerializer.cs
- WebCodeGenerator.cs
- ContextMenuStrip.cs
- OracleBoolean.cs
- ExeConfigurationFileMap.cs
- CustomWebEventKey.cs
- FixedSOMContainer.cs
- MDIWindowDialog.cs
- TransformPattern.cs
- XmlSchemaSimpleContentRestriction.cs
- DataList.cs
- FlagsAttribute.cs
- NameNode.cs
- SafeEventLogWriteHandle.cs
- ConfigurationErrorsException.cs
- AssemblyHash.cs
- ObjectParameterCollection.cs
- ConfigurationSettings.cs
- SettingsSavedEventArgs.cs
- XMLUtil.cs
- AbstractDataSvcMapFileLoader.cs
- BreakRecordTable.cs
- FunctionDetailsReader.cs
- InvariantComparer.cs
- CompositionDesigner.cs
- Calendar.cs
- WindowsRichEdit.cs
- SqlDataSource.cs
- SizeAnimation.cs
- ResourceProviderFactory.cs
- ImageListUtils.cs
- QueryRewriter.cs
- BuildManager.cs
- BinaryObjectWriter.cs
- PointCollection.cs
- autovalidator.cs
- BitmapEffectGroup.cs
- PKCS1MaskGenerationMethod.cs
- CodeTypeOfExpression.cs
- TextRangeProviderWrapper.cs
- SqlDataSource.cs
- ReadOnlyDataSource.cs
- LogConverter.cs
- PartBasedPackageProperties.cs
- HtmlString.cs
- ValidationVisibilityAttribute.cs
- HostedHttpRequestAsyncResult.cs
- ModelFunctionTypeElement.cs
- CacheForPrimitiveTypes.cs
- BitmapCacheBrush.cs
- OdbcUtils.cs
- TransformerInfoCollection.cs
- ChangeProcessor.cs
- Pkcs9Attribute.cs
- RegistryConfigurationProvider.cs
- TextChangedEventArgs.cs
- DataGridHeaderBorder.cs
- SoapSchemaMember.cs
- ValidationErrorCollection.cs
- MailWebEventProvider.cs
- ProbeMatchesMessage11.cs
- ParameterReplacerVisitor.cs
- CardSpacePolicyElement.cs
- DataControlImageButton.cs
- Visual.cs
- SimpleWorkerRequest.cs
- SubstitutionDesigner.cs
- ServiceInfo.cs
- WebPermission.cs
- XamlSerializationHelper.cs
- PreProcessInputEventArgs.cs
- SQLRoleProvider.cs