The Microsoft Foundation Class Library (MFC) and Visual C++ help you debug your applications in a variety of ways. This topic presents a few useful general debugging techniques, followed by more detailed debugging topics.
The Microsoft Foundation Class Library (MFC) contains many diagnostic features to help debug your program during development, such as the Dump and AssertValid member functions, the TRACE and ASSERT macros, the AfxEnableMemoryTracking and AfxDebugBreak global functions, and the CMemoryState class to detect memory leaks.
Because diagnostics slow down and interrupt your application, they are not suitable for a release version. When you are developing your program, you typically build a Win32 Debug version of your program and link with the debug version of MFC. Once the program is completed and debugged, you build a Win32 Release version and link with the release version of MFC. You can easily switch between Win32 Debug and Win32 Release by setting the Select Active Configuration droplist.
Following are several techniques for debugging your MFC application:
DebugBreak( );
which is platform-independent. For MFC applications, you can also use:
AfxDebugBreak( );
This does an
_asm int 3
in Intel versions and calls DebugBreak on other platforms. The advantage (on Intel) is that you break in source code rather than in kernel code.
Be sure to remove these statements when building release-mode applications or include them under #ifdef _DEBUG.
For additional information specific to MFC debugging, see the following topics: