Visual Studio 2005 Express Edition

A Quick Tutorial

Jason Witherell (jwitherell@shawnee.edu)

 

Part I: Getting and Installing VC++:

  • Go To: http://msdn.microsoft.com/vstudio/express/visualc/
  • Make sure you also download Service Pack 1 (SP1): Many projects you download will not work unless you use the newest version of VC++
  • If you plan on writing Windows applications (i.e. not text-based), you will also need to download the Platform SDK.
  • The VC++ page has detailed descriptions of all the above steps.

 

Part II: Creating a VC++ project (Console application: i.e. text-based)

  • To create an .exe file, you must first create a project.  Follow these steps:
  1. Start VC++. 
    • You will see a Start Page with links to recent projects.
  2. Go to File => New => Project…
    • Under Project Types, select Win32
    • Under Templates, choose Win 32 Console Application
    • Enter a Location of click the Browse… button. (for example, C:\temp\Labs)
    • Enter a Project Name (for example, Lab03)
    • Uncheck the Create Directory for Solution.
    • This will create new solution files in C:\temp\Labs\Lab03.
  3. Adding files to the project:
    • If you already have source files created elsewhere:
      • Copy your source files to the solution folder.
      • Go to Project => Add Existing Item…
      • Select your files (Ctrl-click to select multiple files)
      • The new files should be in the solution browser now.
    • If you are making new source files from scratch.
      • Go to Project => Add New Item…
      • Select the appropriate type of file (Usually the Code category, and either .cpp or .files under Templates).
      • Enter a name for the file.
      • The new file will be added to the solution explorer and the new file will be created in the solution directory.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  1. Building a Project
    • This compiles and links your source files into an .exe file.
    • Go to Build => Build Solution (or hit F7).
    • The examples use this source code:

 

 


#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <math.h>

 

#pragma warning(disable: 4996)      // Disable the scanf warning

 

/////////////// Date stuff /////////////////

struct Date

{

      unsigned short day, month, year;

};

 

struct Reading

{

      Date d;

      float temp;

};

 

void PrintDate(struct Reading * r)

{

      printf("%02d/%02d/%04d\t\t(%0.2f)\n", r->d.month, r->d.day, r->d.year, r->temp);

}

 

void PrintDates(struct Reading * dlist , int dsize)

{

int i;

 

      for (i=0; i<dsize; i++)

      {

            printf("%d\t", i);

            PrintDate(&dlist[i]);

      }

}

 

///////////////////////// Recursive stuff ////////////////////////

float recursive_func(int x, int y)

{

      if (x < y)

            return 1.0f;

      else

            return 2.0 * recursive_func(x-2, y+2);

}

 

 

/////////////////////// Main program ////////////////////////////

int main()

{

struct Reading data[50];

int data_size = 50, i, v1, v2;

float result;

 

      for (i=0; i<data_size; i++)

      {

            data[i].d.day = i % 30;

            data[i].d.month = i / 30 + 1;

            data[i].d.year = 2007;

            data[i].temp = (float)(50.0 + sin((float)i / 10.0f) );

      }

      PrintDates(data, data_size);

     

      printf("Integer Value #1: ");

      scanf("%d", &v1);

      printf("Integer Value #2: ");

      scanf("%d", &v2);

      result = recursive_func(v1, v2);

      printf("recursive_func(%d, %d) returned %f\n", v1, v2, result)

 

      return 0;

}

 

 

 


    • I intentionally left off a trainling semi-colon on the 4th-to-last line.
    • If you have no errors, go to step 5.
    • If you do have errors:
      • You will get errors (and warning messages) in the Output Window (usually the bottom of the screen).


 


      • If you double-click on the error/warning line in the Output window, you will be taken directly to the (vicinity of) the error in your source file.

 

    • When your program is free of syntax errors, you will get this output in the Output window:

 

 

  1. Running the Program:
    • When your program is built successfully, you can run it.
    • There are two modes:
      • Run with the Debugger: Hit F5 (see the next section)
      • Run without Debugging: Hit Ctrl-F5.

 

 

Part III: Using the Integrated Debugger

  • The Debugger is a powerful tool to examine your program as it is running, stopping at strategic points in the program to examine memory/variable contents.
  • Successful debugging involves the strategic placing of breakpoints.
    • To set a breakpoint, click on a source code line and press F9
    • Press F9 again to remove the breakpoint.
    • You will see a red dot in the margin next to a line with a set breakpoint.
  • As mentioned, hit F5 to start Debug mode.
    • You code will run until the first breakpoint is encountered:

 

 

 

 

 

 

 

 

    • The use of each area of the debugger is discussed below:
  1. The code view and stepping:
    • The Yellow arrow (), shows the current execution point in the code.
      • (This line is about to be executed).
    • To Step to the next line, hit F10
    • If you want to “Jump-Into” the current line, hit F11
      • If this line contains a function call, this will show execution of that function.
      • If this line contains multiple function calls, this will show the first.
    • If you are in a function, and want to run the rest of the function, returning to the caller, press Shift-F11.
    • To continue running the program to the end (or to the next breakpoint), hit F5 again.
  2. The variables view]
    • There are several sub-panes in this window, discussed below:
    • Autos: Shows all variables active/used-by the current line of code.
    • Locals: Shows all variables within the current scope.
    • Watch1: Shows any variables the user wishes to see.
    • Threads: Shows any active threads (useful for multi-threaded applications)
    • Modules: Shows and DLL’s being used by this program.
    • For the Autos, Locals, and Watch panes:
      • Red entries indicate this variable has been changed since the last statement (or since F5 was hit).
      • You can manually change variable values.
      • A structure or class can be “opened” by clicking the plus beside it (to see the values of attributes/fields).
    • To enter a watch variable, type its name on a blank line.
  3. The call stack view
    • Shows the stack of function activation records.
    • The yellow arrow shows the current context.
    • By double-clicking on a line, you can change the context (it doesn’t affect the current code location).
    • If an area of code has no symbols loaded, you will see the assembly language code.
  4. “File Navigator” view
    • Really useful for class files.  Allows you to select the class in the left drop-down and the method on the right.  You are then taken directly to that source location.
  5. Other views:
    • The Memory and Register Debug views are useful to see the contents of the CPU/Memory at a given time.