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
- infer.cs
- SoapHeaderException.cs
- XsdSchemaFileEditor.cs
- SafeNativeMethodsCLR.cs
- CodePropertyReferenceExpression.cs
- NodeFunctions.cs
- FontFamily.cs
- BrowserTree.cs
- SynthesizerStateChangedEventArgs.cs
- LayoutTableCell.cs
- InternalBufferOverflowException.cs
- PropertyGridDesigner.cs
- UnwrappedTypesXmlSerializerManager.cs
- SystemException.cs
- CursorEditor.cs
- WebServiceData.cs
- LineServicesCallbacks.cs
- RequestStatusBarUpdateEventArgs.cs
- RoutingTable.cs
- GridViewRow.cs
- CompensableActivity.cs
- RpcCryptoContext.cs
- ManipulationDeltaEventArgs.cs
- EventHandlersStore.cs
- Size3DConverter.cs
- UnicastIPAddressInformationCollection.cs
- ReturnEventArgs.cs
- WebControl.cs
- TimeZoneInfo.cs
- Unit.cs
- SortKey.cs
- Select.cs
- typedescriptorpermission.cs
- CreateUserWizardAutoFormat.cs
- NamespaceEmitter.cs
- TableDetailsCollection.cs
- SynchronizedKeyedCollection.cs
- UpdateRecord.cs
- InkCanvasSelection.cs
- smtppermission.cs
- TextElementEnumerator.cs
- XmlDownloadManager.cs
- ObjectViewFactory.cs
- ConsumerConnectionPointCollection.cs
- PermissionSetEnumerator.cs
- X509Certificate2.cs
- LayoutUtils.cs
- ResumeStoryboard.cs
- XsltOutput.cs
- GeneralTransformGroup.cs
- ClaimTypes.cs
- DtcInterfaces.cs
- Merger.cs
- ActivationServices.cs
- PeerDefaultCustomResolverClient.cs
- DataGridViewSelectedRowCollection.cs
- BitStack.cs
- DesignerAttribute.cs
- CommandID.cs
- TreeIterators.cs
- ClientSettingsSection.cs
- TypeConverterMarkupExtension.cs
- HostingPreferredMapPath.cs
- UniqueIdentifierService.cs
- ManagementOperationWatcher.cs
- CompositeKey.cs
- TextTreeRootTextBlock.cs
- DataMemberFieldConverter.cs
- WebPartConnectionsCancelVerb.cs
- ElementUtil.cs
- MailBnfHelper.cs
- QilExpression.cs
- DataGridTableCollection.cs
- ImageFormat.cs
- InlineObject.cs
- StagingAreaInputItem.cs
- PrintSchema.cs
- MatrixAnimationBase.cs
- dbenumerator.cs
- PreviewPrintController.cs
- XpsS0ValidatingLoader.cs
- MemberRelationshipService.cs
- ClientBuildManager.cs
- WebPartTracker.cs
- FormViewDeleteEventArgs.cs
- UIElementIsland.cs
- UntypedNullExpression.cs
- Calendar.cs
- Math.cs
- Set.cs
- SpeechEvent.cs
- SynchronousChannel.cs
- TemplateDefinition.cs
- CreateRefExpr.cs
- DllNotFoundException.cs
- ComplexLine.cs
- SoapHeader.cs
- RuleRef.cs
- CollectionBase.cs
- FlowDocumentReader.cs