Implementing IDebugEngineCreateEvent2
The first event sent by a debug engine is the debug engine create event, represented by the IDebugEngineCreateEvent2 interface. This event lets the session debug manager know that the debug engine is ready.
TextInterpreter implements the IDebugEngineCreateEvent2 on the CEngineCreateEvent class, which is derived from both IDebugEngineCreateEvent2 and CEventBase (all events used by TextInterpreter derive from CEventBase).
To implement IDebugEngineCreateEvent2
In Solution Explorer, right-click the TextInterpreter project and click Add Class.
Add a Generic C++ Class with the Class name CEngineCreateEvent and set its Base class to IDebugEngineCreateEvent2. Set the .h file to EventBase.h and the .cpp file to EventBase.cpp. Make sure that Access is set to public and then click Finish. Answer Yes when the prompts ask if you want to merge with the contents of the specified file.
In Class View, right-click the new class CEngineCreateEvent, click Add Variable, and add a variable with the Variable name m_spEngine, the Variable type CComPtr<IDebugEngine2>, and an Access type of protected.
Open the EventBase.h file, find the declaration for the new class CEngineCreateEvent, and modify the class declaration to look like this:
class CEngineCreateEvent : public IDebugEngineCreateEvent2, public CEventBase {
Modify the constructor declaration for CEngineCreateEvent to add a single parameter, so the line looks like this:
CEngineCreateEvent(IDebugEngine2 *pEngine);
Add the following bold lines. This is the declaration for the IDebugEngineCreateEvent2 interface.
~CEngineCreateEvent(void); //////////////////////////////////////////////////////////// // IDebugEngineCreateEvent2 methods STDMETHOD(GetEngine)(IDebugEngine2 **ppEngine);
Open the EventBase.cpp file and modify the constructor for CEngineCreateEvent to look like this:
CEngineCreateEvent::CEngineCreateEvent(IDebugEngine2 *pEngine) : CEventBase(IID_IDebugEngineCreateEvent2, EVENT_ASYNCHRONOUS) { m_spEngine = pEngine; }
In EventBase.cpp, insert the following bold lines:
CEventBase::~CEventBase(void) { } ////////////////////////////////////////////////////////////////////////////// // IDebugEngineCreateEvent2 HRESULT CEngineCreateEvent::GetEngine(IDebugEngine2 **ppEngine) { *ppEngine = m_spEngine; (*ppEngine)->AddRef(); return S_OK; }
Build the project to make sure there are no errors.