Share via


IDebugDocumentContext2::GetStatementRange

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Gets the file statement range of the document context.

Syntax

HRESULT GetStatementRange(
    TEXT_POSITION* pBegPosition,
    TEXT_POSITION* pEndPosition
);
int GetStatementRange(
    TEXT_POSITION[] pBegPosition,
    TEXT_POSITION[] pEndPosition
);

Parameters

pBegPosition
[in, out] A TEXT_POSITION structure that is filled in with the starting position. Set this argument to a null value if this information is not needed.

pEndPosition
[in, out] A TEXT_POSITION structure that is filled in with the ending position. Set this argument to a null value if this information is not needed.

Return Value

If successful, returns S_OK; otherwise, returns an error code.

Remarks

A statement range is the range of the lines that contributed the code to which this document context refers.

To obtain the range of source code (including comments) within this document context, call the GetSourceRange method.

Example

The following example shows how to implement this method for a simple CDebugContext object that exposes the IDebugDocumentContext2 interface. This example fills in the ending position only if the beginning position is not a null value.

HRESULT CDebugContext::GetStatementRange(TEXT_POSITION* pBegPosition,
                                         TEXT_POSITION* pEndPosition)
{
    HRESULT hr;

    // Check for a valid beginning position argument pointer.
    if (pBegPosition)
    {
        // Copy the member TEXT_POSITION into the local pBegPosition.
        memcpy(pBegPosition, &m_pos, sizeof (TEXT_POSITION));

        // Check for a valid ending position argument pointer.
        if (pEndPosition)
        {
            // Copy the member TEXT_POSITION into the local pEndPosition.
            memcpy(pEndPosition, &m_pos, sizeof (TEXT_POSITION));
        }
        hr = S_OK;
    }
    else
    {
        hr = E_INVALIDARG;
    }

    return hr;
}

See also