Compartir a través de


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

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

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

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

  4. Open the Program.cpp file, find the CProgram::Start method and add the following bold line:

    void CProgram::Start(IDebugEngine2 * pEngine)
    {
        m_spEngine = pEngine; 
    }
    
  5. 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 
    }
    
  6. Open the TextInterpreter.cpp file and add the following bold line:

    #include "Engine.h"
    #include "Program.h" 
    
  7. 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(); 
    
  8. Also in CTextInterpreterModule::MonitorProc, replace the line //TODO: ADD PROGRAM START with the following:

        pProgram->Start(pEngine); 
    
  9. Also in CTextInterpreterModule::MonitorProc, replace the line //TODO: ADD PROGRAM RELEASE with the following:

        pProgram->Release(); 
    
  10. Build the project to make sure there are no errors.

See Also

Concepts

Adding the Program Object