Compartir a través de


Initializing the Debug Engine Object

The TextInterpreter debug engine needs to have a customized version of the ATL module’s MonitorProc method so it can initialize the debug engine object (and later, the program object). TextInterpreter’s version of MonitorProc will access a customized version of the ATL module’s MonitorShutdown method (added in the next step of the tutorial, Adding a Message Pump to MonitorShutdown). However, in order to use a customized version of MonitorProc, it is necessary to also create a customized version of the ATL module’s StartMonitor so that the proper object pointer is used.

If this step is not done, the default StartMonitor supplied by the CAtlExeModuleT<> template class will use its own version of MonitorProc and never call TextInterpreter's version, and TextInterpreter's debug engine object will never be created and initialized.

To initialize the debug engine object

  1. In Class View, right-click the CTextInterpreterModule class and click Add Function to add a public function with the Function nameStartMonitor, a Return type of HANDLE, and no parameters.

  2. In the TextInterpreter.cpp file, find the class declaration for CTextInterpreterModule; after the line that begins DECLARE_REGISTRY_APPID_RESOURCEID, add the following method declaration:

            static DWORD WINAPI MonitorProc(void * pv);
    
  3. At the top of the TextInterpreter.cpp file, add the following bold line:

    #include "TextInterpreter.h"
    #include "Engine.h"
    
  4. In TextInterpreter.cpp, find the newly added CTextInterpreterModule::StartMonitor and insert the following lines into the method:

        m_hEventShutdown = ::CreateEvent(NULL, false, false, NULL);
        if (m_hEventShutdown == NULL)
        {
            return NULL;
        }
        DWORD dwThreadID;
        HANDLE hThread = ::CreateThread(NULL, 0, MonitorProc, this, 0, &dwThreadID);
        if (hThread==NULL)
        {
            ::CloseHandle(m_hEventShutdown);
        }
        return hThread;
    
  5. At the end of the TextInterpreter.cpp file, add the following method definition:

    DWORD WINAPI CTextInterpreterModule::MonitorProc(void * pv)
    {
        CTextInterpreterModule* p = static_cast<CTextInterpreterModule*>(pv);
    
        CoInitialize(NULL);
        CComObject<CEngine> *pEngine;
        CComObject<CEngine>::CreateInstance(&pEngine);
        pEngine->AddRef();
        //TODO: ADD PROGRAM CREATION
    
        //TODO: ADD ENGINE START
        //TODO: ADD PROGRAM START
    
        pEngine->Release();
        //TODO: ADD PROGRAM RELEASE
    
        p->MonitorShutdown();
    
        CoUninitialize();
        return 0;
    }
    
  6. Build the project to make sure there are no errors.

See Also

Concepts

Tutorial: Building a Debug Engine Using ATL COM