IVsTextLines::CopyLineText Method (Int32, Int32, Int32, Int32, IntPtr, Int32)

 

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)

int CopyLineText(
	int iStartLine,
	int iStartIndex,
	int iEndLine,
	int iEndIndex,
	IntPtr pszBuf,
	int% pcchBuf
)

Parameters

iStartLine
Type: System::Int32

[in] Starting line.

iStartIndex
Type: System::Int32

[in] Starting character index within the line. Must be less than or equal to the length of the line.

iEndLine
Type: System::Int32

[in] Ending 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.

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 null 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.

System_CAPS_noteNote

The CopyLineText method does not append null 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.

Return to top
Show: