Thursday, July 1, 2010

Debug "Just My Code" for C++ and MFC

One of my biggest annoyances with debugging MFC code is constantly stepping through CString functions and COM object functions. In Visual C++ 6 there was some functionality in autoexp.dat for handing this, but I never got it to work to my satifaction.

This week I was able to solve the problem. Here's how (note that the 10.0 is for Visual Studio 2010. The value will be 9.0 for VS2008. For earlier versions, see the link at the end of this article.)
  1. Open RegEdit
  2. On 32-bit Windows, go to:

    On 64-bit Windows, go to:

    At least for Visual Studio 2010, there are several default functions defined.
  3. Add a new String value. Name it CStringT.
  4. Edit the key and set the value to:


    The colons must be backslashed as shown. CStringT is the template class used for CString, CStringA and CStringW. The CStringT class is shared with ATL, so that's why it's in the ATL namespace, even if you are using MFC. The "dot star" at the end matches anything for the rest of the line.
  5. Here are a couple of other examples:

    Key: CSimpleString
    Value: ATL\:\:CSimpleStringT.*

    Key: CComPtrBase
    Value: ATL\:\:CComPtrBase.*

    Key: vector
    Value: std\:\:vector.*
Update 7/26/2010: There are additional features documented by Andy Pennell at Microsoft.


  1. Does not work. The registry keys are erased when Visual Studio 2010 starts.

  2. Thanks Anonymous, I'm seeing the same behavior. To be precise, it works fine until you restart VS. I'll work on this more as time allows.

  3. The HKCU\Software\Microsoft\
    VisualStudio\10_Config\ key is a settings cache from HKLM\Software\Microsoft\
    VisualStudio\10\ key and various PKGDEF files. You should be able to change the value under HKLM.

  4. Karl, thanks for the fix! I've updated the text of the article.

  5. Nice job, thanks. One minor point: in step 3, "Add a new String key" should be "Add a new String value"

  6. Anonymous, thanks. I fixed the article.

  7. do the above while vs is not running and your changes will be preserved.