Debugging Preparation: Win32 Projects
Win32 applications are traditional Windows programs written in C or C++. Debugging this type of application in Visual Studio is straightforward.
Win32 applications include MFC applications and ATL projects. They use Windows APIs and may use MFC or ATL, but they do not use the common language runtime (CLR). They can, however, call managed code that uses the CLR.
The following procedure explains how to debug a Win32 project from within Visual Studio. Another way to debug a Win32 application is to start the application outside of Visual Studio and attach to it. For more information, see Attaching to Running Processes.
To debug a C or C++ Win32 application
Open the project in Visual Studio.
On the Debug menu, choose Start.
Debug using the techniques discussed in Debugger Roadmap.
When you create a Windows Application project with the wizard, Visual Studio automatically creates required settings for the Debug and Release configurations. If necessary, you can change those settings. For more information, see How to: Set Debug and Release Configurations.
To manually set a Debug configuration
On the View menu, click Property Pages.
Click the Configuration Properties node to open it if it is not already open.
Select General, and set the value of the Output row to Debug.
Open the C/C++ node, and select General.
In the Debug row you specify the type of debugging information to be generated by the compiler. Values you might choose include Program Database (/Zi) or Program Database for Edit & Continue (/ZI).
Select Optimization, and in the Optimization row, select Disabled (/0d) from the drop-down list.
Optimized code is harder to debug, since the generated instructions do not correspond directly to your source code. If you find your program has a bug that appears only in optimized code, you can turn this setting on, but remember that code shown in the Disassembly window is generated from optimized source that may not match what you see in your source windows. Features such as stepping are likely to show breakpoints and execution point incorrectly.
Open the Linker node, and select Debugging. In the first Generate row, select Yes (/DEBUG) from the drop-down list. Always set this when you are debugging.
For more information, see Project Settings for a C++ Debug Configuration.
See Also
Reference
Project Settings for a C++ Debug Configuration
Other Resources
Debugging Native Code
Debugging Preparation: Visual C++ Project Types