共用方式為


IDebugDocumentContext2::GetStatementRange

取得文件內容的檔案語句範圍。

語法

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

參數

pBegPosition
[in, out]填 入開始位置的TEXT_POSITION 結構。 如果不需要這項資訊,請將這個自變數設定為 Null 值。

pEndPosition
[in, out] 填入結束位置的TEXT_POSITION 結構。 如果不需要這項資訊,請將這個自變數設定為 Null 值。

傳回值

如果成功,則會傳回 S_OK;否則,會傳回錯誤碼。

備註

語句範圍是參與本文件內容所參考程式代碼之行的範圍。

若要取得本文件內容中的原始程式碼範圍(包括批注),請呼叫 GetSourceRange 方法。

範例

下列範例示範如何為公開IDebugDocumentContext2介面的簡單CDebugContext物件實作這個方法。 只有當起始位置不是 Null 值時,本範例才會填入結束位置。

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;
}

另請參閱