Visual Studio 2005 at VTC

Although this document is specifically about Visual Studio 2005, most of what is said here should also apply to Visual Studio 2008 and Visual Studio 2010. The user interfaces of the three programs are not much different. At some point I will update this description to reflect the latest version of Visual Studio.


Introduction

This note briefly describes how to configure a project using Microsoft's Visual Studio 2005. VS 2005 is a huge program with many features. Out of the box it supports C, C++, C#, J#, and Visual Basic .NET programming. However, it allows additional tools to be configured so that using the IDE with other languages is very possible. This note glosses over most of VS 2005's abilities, focusing instead on quickly getting you up to speed with compiling small to medium sized C and C++ programs.


Key Concepts

  1. Like most IDE systems VS 2005 is project based. To get maximum advantage of it you should put each program you work on into a project. Actually VS 2005 uses "solutions" as containers for projects. A single solution might have several different projects inside of it. When you create your first project, it is put into a solution with the same name. You can then either add other projects to your solution or create new solutions for later assignments.

    I recommend one solution per assignment. Multiple projects in a single solution is more suitable for a large, complex programming job that involves many integrated, yet independent programs.

  2. Be aware that VS 2005 projects involve quite a few supporting files (and even supporting folders of files). Thus even a trivial program will have quite a few files as a VS 2005 project. You will definitly want each of your VS 2005 projects (really solutions) in separate folders.

  3. VS 2005 is able to compile code to Microsoft's new Common Language Runtime (CLR) for ".NET applications". If you program in C#, J#, or Visual Basic .NET your only option is to generate CLR code. However, you can configure your C or C++ projects to generate native code. If it is your intention to build an "ordinary" Windows executable be sure to specify this option.


Setting up a VS 2005 project

Here are the basic steps for setting up a native code C/C++ project.

  1. Start the IDE: Start->Programs->Microsoft Visual Studio 2005->Microsoft Visual Studio 2005. If this is the first time you've started VS 2005 it may ask you to describe what sort of development you plan to do. I suggest you select "General Development" from the list of options. The instructions below assume this selection.

  2. You will see a "Start Page" with a section on the left labeled "Recent Projects." At the bottom of that region you can select "Create: project"

  3. On the left side of the "New Project" window, expand "Visual C++ Projects" and select "Win32". On the right side of the window, select "Win32 Console Application". VS 2005 comes with a number of project templates that are configured by default for certain types of projects. By selecting Win32 you are telling the system that you want to build a native code program and not a .NET program.

    In the "Location" text field, type the name of a folder under which you want your project created. In the "Name" text field type the name of your project. VS 2005 will create a containing solution with the same name and a folder with that name for you as well. (NOTE: If you have existing files you want to make part of the project, move them out of the folder temporarily. VS 2005 tends to overwrite existing files without warning).

    graphic

  4. Click "OK". You should then be put into the "Win32 Application Wizard". Click on "Application Settings" and then deselect "Precompiled headers." Also select "Empty project." If you do not select Empty project, VS 2005 creates template source files for you. My experience has been that such files are more trouble than they are worth (at least for the programs we will be writing).

    graphic

  5. Click "Finish". In the Solution Explorer window you should now see a solution open with the same name as your project. Inside that solution there should be a single project with the name you specified. If you look at the folder where you told VS 2005 to put your project you should find several control files there.

    graphic

  6. If you have existing files you want to add to your project, move them back into the project folder. In Solution Explorer right-click on the "Source Files" folder under your project. Select "Add" and then "Add Existing Item" from the pop-up menu. Select your source files. If you have any header files you should add them to the "Header Files" folder under your project (in Solution Explorer... not in the file system). You can also use "Add" and then "Add New Item" to add files to your project that don't yet exist.

    graphic

  7. To build your project (compile and link), select "Build" and then "Build <projectname>" from the main menu. Note that you can also use "Build Solution" since, in our case, there is only one project in a solution. VS 2005 deposits the executable file into a "Debug" folder under the main project folder.

    graphic

If you need additional libraries (for example for network programming) you can add them as follows:

  1. Right-click on the name of your project in Solution Explorer. Select "Properties." Open the "Linker" folder and select "Input". In the property sheet add "WS2_32.lib" to the list of "Additional Dependencies". WS2_32.lib is the Winsock2 library. If you need a different library (or additional libraries) add them as appropriate.

    graphic


Getting Help

If you would like to look up information on a subject, select "Help" and then "Search" from the main menu. This starts Microsoft's document viewer program. Type your search phrase into the form presented and the program will consult several on-line sources to obtain a list of possible references. The amount of help available is quite large (sometimes too large).


© Copyright 2007 by Peter C. Chapin.
Last Revised: December 21, 2007