Customizing the appearence of your own classes in debug windows

Environment: Visual C++ 6

You may have noticed that for example CString instaces do not show up as
`{…}4 in debug windows (watch, variable, etc. and in tooltip when you
move the pointer on a variable). Rather, CString “smartly” shows up as
`{“string”}4. This feature can be customized to make your own classes
appear smartly while debugging, so that you can see the most crucial
member varibles at first glance rather than having to expand the
non-meaningful `{…}4 at first.

The definitions for the custom formatting reside in autoexp.dat in
CommonMSDev98Bin directory. The file has a fairly good documentation in
it, and some good examples as well (including the CString one.) As with
the usertype.dat (that has been dealt with in another article here), you’ll
have to restart MSVC to have the changes take effect.

This is a snippet from the file itself – it explains the syntax quite well.


; type=[text]
;
; type Name of the type (may be followed by <*> for template
; types such as the ATL types listed below).
;
; text Any text.Usually the name of the member to display,
; or a shorthand name for the member.
;
; member Name of a member to display.
;
; format Watch format specifier. One of the following:
;
; Letter Description Sample Display
; —— ————————– ———— ————-
; d,i Signed decimal integer 0xF000F065,d -268373915
; u Unsigned decimal integer 0x0065,u 101
; o Unsigned octal integer 0xF065,o 0170145
; x,X Hexadecimal integer 61541,X 0X0000F065
; l,h long or short prefix for 00406042,hx 0x0c22
; d, i, u, o, x, X
; f Signed floating-point 3./2.,f 1.500000
; e Signed scientific-notation 3./2.,e 1.500000e+000
; g Shorter of e and f 3./2.,g 1.5
; c Single character 0x0065,c ‘e’
; s Zero-terminated string 0x0012fde8,s “Hello world”
; su Unicode string 0x007200c4,su “Hello world”
; st String in ANSI or Unicode depending on current setting
;
; The special format <,t> specifies the name of the most-derived
; type of the object. This is especially useful with pointers or
; references to a base class.
;
; If there is no rule for a class, the base classes are checked for
; a matching rule.

For example, the line for CString is


CString =<m_pchData,st>

If you have a class like this,


class Goo
{
int width;
double height;
char* name;
};

you might define the apperance as follows:


Goo =<name,s> width: <width,i> height: <height,g>

which would result in the following outlook in the debug window:


{“a goo” width: 5 height: 3.1}

Date Last Updated: April 18, 1999

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read