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
- ProgressPage.cs
- RadioButton.cs
- ImageAutomationPeer.cs
- PieceNameHelper.cs
- PackagePartCollection.cs
- AmbientLight.cs
- DataTrigger.cs
- InputBuffer.cs
- TreeViewEvent.cs
- Vector3DAnimation.cs
- Inflater.cs
- BlurBitmapEffect.cs
- Table.cs
- PropertyRecord.cs
- MetadataSource.cs
- HttpRequestCacheValidator.cs
- QilTernary.cs
- RightsManagementPermission.cs
- UrlMappingCollection.cs
- DataGridViewRowEventArgs.cs
- TrackingLocation.cs
- PackageRelationship.cs
- Table.cs
- RealizedColumnsBlock.cs
- MouseActionConverter.cs
- PermissionRequestEvidence.cs
- EventLog.cs
- WriteTimeStream.cs
- UmAlQuraCalendar.cs
- WebPermission.cs
- DynamicEndpoint.cs
- DependencySource.cs
- AnimationLayer.cs
- SelectionChangedEventArgs.cs
- ViewCellSlot.cs
- InstalledFontCollection.cs
- EditorAttribute.cs
- RuntimeIdentifierPropertyAttribute.cs
- MouseEvent.cs
- RelationshipSet.cs
- TypeDescriptionProvider.cs
- SerializationTrace.cs
- XmlNodeWriter.cs
- SourceFileInfo.cs
- Transform3D.cs
- SerialErrors.cs
- SoapHeaders.cs
- figurelength.cs
- DynamicMethod.cs
- SQLByteStorage.cs
- NotifyParentPropertyAttribute.cs
- TextAdaptor.cs
- XmlUrlResolver.cs
- PropertyRecord.cs
- DecoderBestFitFallback.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- SafeHandles.cs
- PointHitTestResult.cs
- RenderDataDrawingContext.cs
- PackagingUtilities.cs
- SQLString.cs
- HyperlinkAutomationPeer.cs
- FlowDocumentView.cs
- FileCodeGroup.cs
- UnsafeNativeMethods.cs
- HtmlTableRow.cs
- CodeArgumentReferenceExpression.cs
- DataSourceXmlTextReader.cs
- XmlSchemaDocumentation.cs
- ApplicationSecurityManager.cs
- SqlDataReader.cs
- DirectoryNotFoundException.cs
- RsaSecurityTokenParameters.cs
- Console.cs
- WebBrowser.cs
- TabControl.cs
- LazyTextWriterCreator.cs
- Knowncolors.cs
- TypefaceCollection.cs
- CodeTypeConstructor.cs
- ObjectItemNoOpAssemblyLoader.cs
- XD.cs
- OleDbError.cs
- EventlogProvider.cs
- SynchronousChannelMergeEnumerator.cs
- EndpointDispatcher.cs
- SqlCacheDependencySection.cs
- EntityDescriptor.cs
- LoadMessageLogger.cs
- ClientRuntimeConfig.cs
- EventData.cs
- FontDriver.cs
- AutoGeneratedField.cs
- RegionInfo.cs
- Socket.cs
- WebPartCatalogAddVerb.cs
- ConsoleKeyInfo.cs
- FutureFactory.cs
- Pair.cs
- PersistenceParticipant.cs