IVsTextLines.CopyLineText Method

Puts the specified span of text into a caller-allocated buffer (an array).

Namespace:  Microsoft.VisualStudio.TextManager.Interop
Assembly:  Microsoft.VisualStudio.TextManager.Interop (in Microsoft.VisualStudio.TextManager.Interop.dll)

Syntax

声明
Function CopyLineText ( _
    iStartLine As Integer, _
    iStartIndex As Integer, _
    iEndLine As Integer, _
    iEndIndex As Integer, _
    pszBuf As IntPtr, _
    <OutAttribute> ByRef pcchBuf As Integer _
) As Integer
int CopyLineText(
    int iStartLine,
    int iStartIndex,
    int iEndLine,
    int iEndIndex,
    IntPtr pszBuf,
    out int pcchBuf
)
int CopyLineText(
    [InAttribute] int iStartLine, 
    [InAttribute] int iStartIndex, 
    [InAttribute] int iEndLine, 
    [InAttribute] int iEndIndex, 
    [InAttribute] IntPtr pszBuf, 
    [InAttribute] [OutAttribute] int% pcchBuf
)
abstract CopyLineText : 
        iStartLine:int * 
        iStartIndex:int * 
        iEndLine:int * 
        iEndIndex:int * 
        pszBuf:IntPtr * 
        pcchBuf:int byref -> int 
function CopyLineText(
    iStartLine : int, 
    iStartIndex : int, 
    iEndLine : int, 
    iEndIndex : int, 
    pszBuf : IntPtr, 
    pcchBuf : int
) : int

Parameters

  • iStartIndex
    Type: System.Int32
    [in] Starting character index within the line. Must be less than or equal to the length of the line.
  • iEndIndex
    Type: System.Int32
    [in] Ending character index within the line. Must be less than or equal to the length of the line.
  • pszBuf
    Type: System.IntPtr
    [in] Pointer to a caller-allocated buffer.
  • pcchBuf
    Type: System.Int32%
    [in, out] Pointer to a count of Unicode characters — not bytes.

Return Value

Type: System.Int32
If the method succeeds, it returns S_OK. If it fails, it returns an error code.

Remarks

COM Signature

From textmgr.idl:

HRESULT IVsTextLines::CopyLineText(
   [in] long iStartLine,
   [in] CharIndex iStartIndex,
   [in] long iEndLine,
   [in] CharIndex iEndIndex,
   [in] LPWSTR pszBuf,
   [in, out] long *pcchBuf
);

To determine the size of the array necessary to hold a given span of text, call IVsTextLines.CopyLineText and pass in the starting and ending positions in the buffer and nulla null reference (Nothing in Visual Basic) for the pszBuf parameter. This method then returns the size of the array in the pcchBuf parameter.

This method copies up to pcchBuf characters into the buffer you allocate. If the buffer is not large enough to hold these characters, the method returns BUFFER_E_DEST_TOO_SMALL and sets the pcchBuf parameter to the required size.

备注

The CopyLineText method does not append nulla null reference (Nothing in Visual Basic) to the output string.

IVsTextLines.CopyLineText is used as an optimization over methods that require the buffer to allocate the memory for them, such as GetLineText. In the case of this method, the text buffer allocates a BSTR, which has a fairly significant performance cost if the method is called repeatedly. For IVsTextLines.CopyLineText, however, you can repeatedly copy over the buffer you allocate if you call this method repeatedly.

.NET Framework Security

See Also

Reference

IVsTextLines Interface

Microsoft.VisualStudio.TextManager.Interop Namespace