Implementing SendEvent
CEventBase::SendEvent is a helper method that sends an event back to the session debug manager (SDM). It handles both asynchronous and synchronous events. An asynchronous event is sent to the SDM, and SendEvent returns immediately. On the other hand, if a synchronous event is sent to the SDM, SendEvent enters a message pump to wait for a sign (that is, a message) that the SDM has finished (since the SDM always returns immediately from a call to IDebugEventCallback2::Event). When SendEvent receives the message, it exits the message pump and returns to its caller, thus ending the synchronous event handling.
In this procedure, you implement the basic functionality of SendEvent; in the next procedure, you implement the necessary code to break out of the synchronizing loop.
To implement SendEvent
In Class View, right-click the CEventBase class, select Add Function, and add a function with the Function name SendEvent, a Return type of HRESULT, an Access type of public, and the following parameters in the given order (click Add between each parameter to add it to the Parameter list):
Parameter Type
Parameter Name
IDebugEventCallback2 *
pCallback
IDebugEngine2 *
pEngine
IDebugProgram2 *
pProgram
IDebugThread2 *
pThread
Open the EventBase.cpp file, find CEventBase::SendEvent, and replace the line return E_NOTIMPL; with the following:
AddRef(); // Send the event to the SDM HRESULT hr = pCallback->Event( pEngine, NULL, pProgram, pThread, (IDebugEvent2 *) this, m_riid, m_dwAttrib); // If event is synchronous, pump messages and wait for continuation. if (SUCCEEDED(hr) && (m_dwAttrib == EVENT_SYNCHRONOUS)) { MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { //TODO: ADD CONTINUE EVENT TEST DispatchMessage(&msg); } } Release(); return hr;
Build the project to make sure there are no errors.