Writing the Metrics to the Registry

For the TextInterpreter debug engine to be available to Visual Studio, the debug engine must be registered. This is done by setting certain registry values. A collection of helper functions and declarations is supplied with the Debugging SDK (see Debugger SDK Helpers). These helper functions are declared in dbgmetric.h and linked to in dbgmetric.lib, and make registering and unregistering the debug engine a straightforward process.

While the TextInterpreter debug engine is running, it is registered with Visual Studio. When the debug engine terminates, it unregisters itself.

To register and unregister program metrics

  1. Open the TextInterpreter.cpp file and add the following bold line. This specifies the base registry key for Visual Studio.

    #include "Program.h"
    
    static const WCHAR strRegistrationRoot[] = L"Software\\Microsoft\\VisualStudio\\8.0Exp"; 
    
    class CTextInterpreterModule : public CAtlExeModuleT< CTextInterpreterModule >
    

    Note

    The registry key specified in strRegistrationRoot is for an experimental root common to VSIP samples. Visual Studio can be invoked to use a different registry key root so as to allow for experimentation without interfering with installed programs. Since TextInterpreter will be invoked from the MyCPkgs VSIP sample, it is necessary to use the same registry root that the sample expects.

  2. Also in the TextInterpreter.cpp file, add the following bold lines to the CTextInterpreter class declaration. This will make it easier to reference the base class.

    class CTextInterpreterModule : public CAtlExeModuleT< CTextInterpreterModule >
    {
    private: 
        typedef CAtlExeModuleT<CTextInterpreterModule> base; 
    public :
    
  3. In Class View, right-click the CTextInterpreterModule class, select Add Function, and add a function with the Function name RegisterServer that has a Return type of HRESULT, an Access type of public, and the following parameters in the order given (click Add between each parameter to add it to the Parameter list). This overrides the base class version of this method.

    Parameter Type

    Parameter Name

    BOOL

    bRegTypeLib

    const CLSID *

    pCLSID

  4. Right-click the CTextInterpreterModule class again, select Add Function, and add a function with the Function name UnregisterServer that has a Return type of HRESULT, an Access type of public, and the following parameters in the order given (click Add between each parameter to add it to the Parameter list). This overrides the base class version of this method.

    Parameter Type

    Parameter Name

    BOOL

    bUnRegTypeLib

    const CLSID *

    pCLSID

  5. Open the TextInterpreter.cpp file and modify the declarations for RegisterServer and UnregisterServer in the CTextInterpreterModule class to specify a default value of 0 for each parameter except bUnRegTypeLib. The declarations should look like this:

        HRESULT RegisterServer(BOOL bRegTypeLib = 0, const CLSID * pCLSID = 0); 
        HRESULT UnregisterServer(BOOL bUnRegTypeLib, const CLSID * pCLSID = 0); 
    
  6. In TextInterpreter.cpp, find the definition for CTextInterpreterModule::RegisterServer and replace the line return E_NOTIMPL; with the following:

        SetMetric(metrictypeEngine, __uuidof(Engine), 
            metricName, L"Text File", 
            false, strRegistrationRoot); 
        SetMetric(metrictypeEngine, __uuidof(Engine), 
            metricCLSID, CLSID_Engine, 
            false, strRegistrationRoot); 
        SetMetric(metrictypeEngine, __uuidof(Engine), 
            metricProgramProvider, CLSID_MsProgramProvider, 
            false, strRegistrationRoot); 
    
        return base::RegisterServer(bRegTypeLib, pCLSID); 
    
  7. In the definition for CTextInterpreterModule::UnregisterServer, replace the line return E_NOTIMPL; with the following:

        RemoveMetric(metrictypeEngine, __uuidof(Engine), metricName, strRegistrationRoot); 
        RemoveMetric(metrictypeEngine, __uuidof(Engine), metricCLSID, strRegistrationRoot); 
        RemoveMetric(metrictypeEngine, __uuidof(Engine), metricProgramProvider, strRegistrationRoot); 
    
        return base::UnregisterServer(bUnRegTypeLib, pCLSID); 
    
  8. At this point, it is necessary to Rebuild the entire project to make sure there are no errors. Some of the additions made so far will cause the precompiled header to become out of date, and it is not updated during a normal build.

See Also

Tasks

Tutorial: Building a Debug Engine Using ATL COM

Reference

Debugger SDK Helpers