Implementing CDebugContext
In TextInterpreter, CPendingBreakpoint::Bind (the implementation for IDebugPendingBreakpoint2::Bind) creates an instance of CDebugContext and then calls CDebugContext::Initialize with the documentation name and position of the breakpoint. This information is returned from the few methods on the IDebugDocumentContext2 interface that are actually implemented here.
To implement CDebugContext
In Class View, right-click the CDebugContext class, click Add Variable, and add a variable with the Variable name m_sbstrFileName, a Variable type of CComBSTR, and an Access type of protected.
Add another variable to the CDebugContext class with the Variable name m_pos, a Variable type of TEXT_POSITION, and an Access type of protected.
In Class View, right-click the CDebugContext class and click Add Function to add a function with the Function name Initialize, a Return type of void, and the following parameters in the order given (click Add between each one):
Parameter type
Parameter name
LPCWSTR
pszFileName
TEXT_POSITION&
pos
Open the Context.cpp file, find CDebugContext::Initialize, and add the following bold lines:
void CDebugContext::Initialize(LPCWSTR pszFileName, TEXT_POSITION& pos) { m_sbstrFileName = pszFileName; m_pos = pos; }
In CDebugContext::GetDocumentContext, replace the line //TODO: RETURN DOCUMENT CONTEXT as well as the following return statement with the following:
*ppSrcCxt = (IDebugDocumentContext2 *) this; (*ppSrcCxt)->AddRef(); return S_OK;
In CDebugContext::GetName, replace the line //TODO: RETURN CONTEXT FILENAME as well as the following return statement with the following:
*pbstrFileName = SysAllocString(m_sbstrFileName); return S_OK;
In CDebugContext::GetSourceRange, replace the line //TODO: RETURN SOURCE RANGE as well as the following return statement with the following. Note that the range is always zero characters, so the beginning and end positions are always the same.
if (pBegPosition) *pBegPosition = m_pos; if (pEndPosition) *pEndPosition = m_pos; return S_OK;
In CDebugContext::GetStatementRange, replace the line //TODO: RETURN STATEMENT RANGE as well as the following return statement with the following. Note that because the document and code contexts are the same, the ranges are also the same.
return GetSourceRange(pBegPosition, pEndPosition);
Build the project to make sure there are no errors.