Implementing the Program Destroy Event

The event represented by the IDebugProgramDestroyEvent2 interface is sent by the debug engine to the session debug manager when the program being debugged is terminated.

In TextInterpreter, the IDebugProgramDestroyEvent2 interface is implemented on the CProgramDestroyEvent class.

To implement CProgramDestroyEvent

  1. In Solution Explorer, right-click the TextInterpreter project and click Add Class.

  2. Add a Generic C++ Class with the Class name CProgramDestroyEvent and set its Base class to IDebugProgramDestroyEvent2. Set the .h file to EventBase.h and the .cpp file to EventBase.cpp. Make sure that Access is set to public. Click Finish. Answer Yes to the prompts that ask if you want to merge with the contents of the specified file.

  3. In Class View, right-click the new CProgramDestroyEvent class, click Add Variable, and add a variable with the Variable name m_dwExitCode, a Variable type of DWORD, and an Access type of protected.

  4. Open the EventBase.h file, find the declaration for the new class CProgramDestroyEvent, and modify the class declaration to look like the following:

    class CProgramDestroyEvent :
        public IDebugProgramDestroyEvent2, 
        public CEventBase 
    
  5. After the declaration of the CProgramDestroyEvent destructor, add the following bold lines. These are the declarations for the methods on the IUnknown and IDebugProgramDestroyEvent2 interfaces.

        ~CProgramDestroyEvent();
    
        ///////////////////////////////////// 
        // IUnknown methods 
        DECLARE_IUNKNOWN 
    
        ///////////////////////////////////// 
        // IDebugProgramDestroyEvent2 methods 
        STDMETHOD(GetExitCode)(DWORD *pdwExit); 
    
  6. In EventBase.h, modify the CProgramDestroyEvent constructor to take one parameter like this:

        CProgramDestroyEvent(DWORD dwExitCode);
    
  7. Open the EventBase.cpp file, find the CProgramDestroyEvent class, and modify the constructor to look like the following:

    CProgramDestroyEvent::CProgramDestroyEvent(DWORD dwExitCode)
    : CEventBase(IID_IDebugProgramDestroyEvent2, EVENT_ASYNCHRONOUS) 
    {
       m_dwExitCode = dwExitCode; 
    }
    
  8. After the CProgramDestroyEvent class destructor, add the following bold lines. These are the definitions for the methods on the IUnknown and IDebugProgramDestroyEvent2 interfaces.

    CProgramDestroyEvent::~CProgramDestroyEvent()
    {
    }
    
    ////////////////////////////////////////////////////////////////////////////// 
    // IUnknown 
    IMPLEMENT_IUNKNOWN(CProgramDestroyEvent, IDebugProgramDestroyEvent2) 
    
    ////////////////////////////////////////////////////////////////////////////// 
    // IDebugProgramDestroyEvent2 
    HRESULT CProgramDestroyEvent::GetExitCode(DWORD *pdwExit) { 
       *pdwExit = m_dwExitCode; 
       return S_OK; 
    }
    
  9. Build the project to make sure there are no errors.

See Also

Concepts

Terminating the Text Interpreter