Instantiating the Program Object
You instantiate the program object at the same time that the debug engine is instantiated by using CComObject::CreateInstance. It is also necessary to connect the debug engine and the program object. To accomplish these two tasks, you first add code to connect the debug engine to the program. Second, you add code to instantiate the program object. Third, you connect the program to the debug engine.
To instantiate the program object
In Class View, right-click the CProgram class and click Add Function to add a public function with the Function name Start, a Return type of void, and the following parameter (be sure to click Add to add the parameter to the Parameter list).
Parameter Type
Parameter Name
IDebugEngine2 *
pEngine
Right-click the CProgram class again, click Add Function to add a public function with the Function name EngineAttach, a Return type of void, and the following parameters (be sure to click Add to add the parameters to the Parameter list).
Parameter Type
Parameter Name
IDebugProgram2 *
pMDMProgram
IDebugEventCallback2 *
pCallback
DWORD
dwReason
Right-click the CProgram class again and click Add Variable to add a variable with the Variable name m_spEngine, a Variable type of CComPtr<IDebugEngine2>, and an Access type of protected.
Open the Program.cpp file, find the CProgram::Start method and add the following bold line:
void CProgram::Start(IDebugEngine2 * pEngine) { m_spEngine = pEngine; }
Also in the Program.cpp file, find the CProgram::EngineAttach method and add the following bold lines (these lines are going to be completed in later steps):
void CProgram::EngineAttach(IDebugProgram2* pMDMProgram, IDebugEventCallback2* pCallback, DWORD dwReason) { //TODO: GET PROGRAM GUID //TODO: ADD CREATE EVENT NOTIFICATIONS //TODO: ADD LOAD EVENT NOTIFICATION }
Open the TextInterpreter.cpp file and add the following bold line:
#include "Engine.h" #include "Program.h"
In TextInterpreter.cpp, find the CTextInterpreterModule::MonitorProc method and replace the line //TODO: ADD PROGRAM CREATION with the following:
CComObject<CProgram> *pProgram; CComObject<CProgram>::CreateInstance(&pProgram); pProgram->AddRef();
Also in CTextInterpreterModule::MonitorProc, replace the line //TODO: ADD PROGRAM START with the following:
pProgram->Start(pEngine);
Also in CTextInterpreterModule::MonitorProc, replace the line //TODO: ADD PROGRAM RELEASE with the following:
pProgram->Release();
Build the project to make sure there are no errors.