Differences between revisions 4 and 6 (spanning 2 versions)
Revision 4 as of 2008-01-23 14:45:55
Size: 5565
Editor: mpino1301
Comment: How to enable debugging
Revision 6 as of 2008-01-23 15:04:12
Size: 5939
Editor: mpino1301
Comment: How to enable debugging
Deletions are marked like this. Additions are marked like this.
Line 90: Line 90:
=== Starting a project from scratch without a wizard ===
Line 91: Line 93:
Start Visual Studio via the Start menu. Go to the menu
Line 93: Line 94:
File -> New -> Project -> General -> Empty Project  * Start Visual Studio via the Start menu. Go to the menu
Line 95: Line 96:
As name, say "TestProject", as location say "D:\"  File -> New -> Project -> General -> Empty Project
Line 97: Line 98:
Note that this will also create a soltuon called "TestProject", with a subproject called "TestProject". You can add other subprojects later.  As name, say "TestProject", as location say "D:\". Note that this will also create a solution called "TestProject", with a subproject called "TestProject". You can add other subprojects later.
Line 99: Line 100:
To create the "Hello World" source file, go to  * To create the "Hello World" source file, go to
Line 101: Line 102:
Source Files -> Add -> New Item -> Code -> C++ File  Source Files -> Add -> New Item -> Code -> C++ File
Line 103: Line 104:
As name, say "helloworld.cpp".  As name, say "helloworld.cpp".
Line 105: Line 106:
Enter the program from above into the editor subwindow.  * Enter the program from above into the editor subwindow.
Line 107: Line 108:
To build the project, go to  * To build the project, go to
Line 109: Line 110:
Build -> Build TestProject (or to Build -> Build Solution)  Build -> Build TestProject (or to Build -> Build Solution)
Line 111: Line 112:
To run the program, go to  * To run the program, go to
Line 113: Line 114:
Debug -> Start Without Debugging  Debug -> Start Without Debugging
Line 135: Line 136:
There are 3 ways to prevent the Command Prompt (DOS box) from disappearing after the last line has been executed:

 * Ctrl+F5 to run without debugging
 * Set a break point at the end
 * Put Console.Read(); (or Console.ReadLine();) at the end of the program

=== Usual work cycle ===

Developing applications under MS-Windows

This page is mainly written for UNIX developers who want to become familiar with MS development.

First read or skim through the [http://msdn2.microsoft.com/en-us/library/xw1ew2f8(VS.80).aspx Introduction to Visual C++ for UNIX Users] on the [http://msdn2.microsoft.com/en-us/default.aspx Microsoft Developer Network].

(MSDN is Microsoft’s website for software developers. It provides resources that explain how to build software solutions and applications on the Microsoft platform.)

Compiling and running "Hello World" on the command line

Use any editor of your choice to create the following program in a test folder:

#include <stdio.h>

int main()
{
        printf("Hello world!\n");
}

Open a DOS box ("Command Prompt"), cd to your test directory, and perform the following steps:

D:\test>dir
 Volume in drive D is WIN_DAT
 Volume Serial Number is F00B-2B98

 Directory of D:\test

01/23/2008  01:31 PM    <DIR>          .
01/23/2008  01:31 PM    <DIR>          ..
01/23/2008  01:31 PM                68 helloworld.c
               1 File(s)             68 bytes
               2 Dir(s)  14,618,644,480 bytes free

D:\test>"C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
Setting environment for using Microsoft Visual Studio 2005 x86 tools.

D:\test>cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

D:\test>cl helloworld.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

helloworld.c
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:helloworld.exe
helloworld.obj

D:\test>dir
 Volume in drive D is WIN_DAT
 Volume Serial Number is F00B-2B98

 Directory of D:\test

01/23/2008  01:39 PM    <DIR>          .
01/23/2008  01:39 PM    <DIR>          ..
01/23/2008  01:31 PM                68 helloworld.c
01/23/2008  01:39 PM            53,248 helloworld.exe
01/23/2008  01:39 PM               612 helloworld.obj
               3 File(s)         53,928 bytes
               2 Dir(s)  14,618,583,040 bytes free

D:\test>helloworld
Hello world!

Note: If you open a command prompt with the Visual Studio Command Line Prompt from the Start menu, then vsvars32.bat is run for you.

Using the Development Environment

It is easier to use the development environment to edit and build your source code in a project. A project is a collection of source and related files that will be compiled into a single unit, such as a library or executable. A project also contains information on how the files are to be built. Information about projects is stored in a project file with the extension .prj.

An application that consists of multiple libraries and executables, each potentially built with a different set of compiler options or even in a different language, are stored in multiple projects that are part of a single solution. A solution is an abstraction for a container to group multiple projects together. Information about solutions is stored in a solution file with the extension .sln.

You can create new projects in the development environment. Visual C++ provides numerous templates that provide standard code for various common projects. You can use application wizards to generate projects with code outlines for various application types.

You can start with an empty project by using the Console Application (Win32) Wizard. Select the Empty Project check box. You can then add new and existing files to the project later.

Starting a project from scratch without a wizard

To start with an empty project without a wizard, do the following:

  • Start Visual Studio via the Start menu. Go to the menu

    File -> New -> Project -> General -> Empty Project

    As name, say "TestProject", as location say "D:\". Note that this will also create a solution called "TestProject", with a subproject called "TestProject". You can add other subprojects later.

  • To create the "Hello World" source file, go to

    Source Files -> Add -> New Item -> Code -> C++ File As name, say "helloworld.cpp".

  • Enter the program from above into the editor subwindow.
  • To build the project, go to

    Build -> Build TestProject (or to Build -> Build Solution)

  • To run the program, go to

    Debug -> Start Without Debugging

How to enable debugging

(For a discussion why debugging is not enabled by default see [http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=811132&SiteID=1 here].)

  1. Goto Project->TestProject Properties

  2. On the left expand "Configuration Properties"
  3. Expand "C/C++"
  4. On the left, Select "General"
  5. On the right, change "Debug Information Format" to "Program Database For Edit And Continue (/ZI)"
  6. On the left, Select "Optimization"
  7. On the right, change "Optimization" to "Disabled (/Od)"
  8. On the left, expand "Linker"
  9. On the left, select "Debugging"
  10. On the right, change "Generate Debug Info" to "Yes"
  11. Click ok
  12. Set your breakpoints: Point to a line, right mouse click, Breakpoint -> Set Breakpoint

  13. Build -> Rebuild TestProject

  14. Debug -> Start Debugging

There are 3 ways to prevent the Command Prompt (DOS box) from disappearing after the last line has been executed:

  • Ctrl+F5 to run without debugging
  • Set a break point at the end
  • Put Console.Read(); (or Console.ReadLine();) at the end of the program

Usual work cycle

From now on, the usual work cycle is

  1. Add more files and/or edit your code
  2. Press F7 (Build Solution)
  3. Press F5 (Start Debugging)

CompleteSearch: completesearch/DevelopingUnderWindows (last edited 2011-07-28 22:00:41 by p57B0BAF6)