Static Linking MFC and CRT

This tutorial describes setting up Coverage Validator to include or exclude different source files from coverage processing when you statically link your application with MFC and/or the C Runtime.

When you statically link to MFC and/or the CRT, the code for the MFC and/or CRT libraries is included in your application. This means that Coverage Validator’s filtering by DLL policy will not work, as DLLs are not used to provide MFC and/or CRT support for statically linked applications.

This means that Coverage Validator needs to know where the source code for your application, source code for 3rd parties (MFC, CRT, etc.) and any other source code is kept so that this source code can be filtered out of the code coverage results.

  • Open the settings dialog by clicking the tools icon on the toolbar.
    Coverage Validator settings toolbar
  • The Settings Dialog is displayed. Select the File Locations tab.
    Coverage Validator PDB File Locations
  • Set the Path Type to “Source Files”, and using the File Scan… display the file search dialog. Select Directory search and then either type the directory name or click Browse… and use the Microsoft directory chooser dialog to select the directory you want to scan. Click OK to start the search for your source files.
    Coverage Validator Source file search
  • When you see the search results, edit the directories to remove any you don’t want or add additional directories. The result will be shown on the File Locations dialog.
    Coverage Validator File Locations source files settings
  • Set the Path Type to “Third Party Source Files”, and then click File Scan… to display the file scan dialog. Select Visual Studio Search, then choose the version of Visual Studio you are using. Click OK to start the search for third-party source files.
    Coverage Validator file locations visual studio search
  • When the search has completed select the file paths that identify the locations of your application’s 3rd party source code (MFC, CRT, 3rd party vendor controls, etc.).
    Coverage Validator File Locations third party source files settings
  • Select the Hook Insertion tab and configure the Source Code Line Hook Insertion settings as shown.
    Coverage Validator static linking hook insertion settings
  • Click OK to save the settings.

Conclusion

You have learned how to configure the settings for working with applications statically linked to libraries that you do not wish to be considered for code coverage.

In this example, C runtime and MFC libraries that are statically linked to the test application will not be considered for code coverage.

  • Select the checkboxes in the section marked Source Code Line Hook Insertion. The image shows that 3rd party source code has been marked to be ignored (deselected).

Fully functional, free for 30 days