Sei sulla pagina 1di 6

Getting Started with Visual Studio 2005 Express Edition

By Dale E. La Force
www.gameinstitute.com

This article describes, step-by-step, how to setup, compile, and run the first C++ sample
program in C++ Programming for Games Module I using the Visual Studio 2005
Express Edition (http://msdn.microsoft.com/vstudio/express/visualc/default.aspx).
Before continuing this article, make sure that you have downloaded and installed the
Visual Studio 2005 Express Edition, as well as the MSDN Library for VS2005 and the
Platform SDK.
Before we start, it is important to ensure that our Environment is setup properly.
From the Tools menu select Options->Projects and Solutions->VC++ Directories.
Add the following paths to the appropriate subsection (see Figure 1).

• Executable files: C:\Program Files\Microsoft SDK\Bin


• Include files: C:\Program Files\Microsoft SDK\Include
• Library files: C:\Program Files\Microsoft SDK\Lib
Note that these locations are the default location. If you installed the SDK in another
location, then you will need to make the necessary path changes to reflect that.

Figure 1: Select the upper-right drop down list to switch between Executable Files, Include Files, and
Library Files.
Next, we need to update the corewin_express.vsprops file located in the C:\Program
Files\Microsoft Visual Studio8\VC\VCProjectDefaults folder. Use notepad to open this
file and make the following changes. Change AdditionalDependencies = “kernel32.lib”
to:

AdditionalDependencies = “kernel32.lib user32.lib gdi32.lib winspool.lib


comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib”

Now we can develop win32 console and windows applications.


After launching Visual Studio 2005 Express Edition, go to File->New->Project.
The following dialog should appear—Figure 2.

Figure 2: The New Project dialog.

Under Project types, click Win32 to highlight it. In the box labeled Templates,
click on Win32 Console Application. Enter a name for the project in the box pointed to
by the arrow next to Project Name in the above image. Notice that the Solution name is
the same as the project name. You can change this, however for this example we will
leave it as shown. Now click the OK button. A new dialog box will appear—Figure 3.
Figure 3: Win32 Application Wizard Dialog.

Click on Application Settings to go to the next dialog; it should look like Figure 4.

Figure 4: Win32 Application Wizard Dialog—Application Settings.

Ensure that Console application is selected and that Empty project is checked
under Additional options. After verifying that the correct selections have been made,
click the Finish button.
We now have a skeleton project to work with. There are, of course, no files in our
project at this time. Our next step will be to add a .CPP file to the project. From the top
menu select Project->Add new item. You will be presented with the dialog in Figure 5.
Figure 5: Adding a new CPP file to the project.

Click on Code in the Categories box. In the Template box click on C++ File
(.cpp ). Give the file a name; a common name would be “main” in a single file console
application. Now click Add. You should have a blank .CPP source file showing in the
main window of the IDE as well as the .CPP file under the source folder in the Solution
Explorer.
Now we want to add some code to our new source file. Add the following code to
the blank .CPP file:

//*************************************************************
// print string by Frank Luna
//*************************************************************

#include <iostream>
#include <string>

int main()
{
std::string firstName = “” ;
std::cout << “Enter your first name and press Enter : “;
std::cin >> firstName;
std::cout << endl;
std::cout << “ Hello, “ << firstName << std::endl << std::endl;
}

After the C++ source code has been entered, it must be translated into a language the
computer understands. There are two steps in the translation process.
1. Compilation
2. Linking

From the top menu select Build->Compile. At the bottom of the IDE, you should see the
Output window that shows zero errors and zero warnings. You will see all compiler
complaints and other information in this window when compiling and linking projects;
Figure 6 shows an example of the Output window.

Figure 6: The Output window after compiling.

After compilation has completed and is successful, it is time to link the code. This
is also called the build. From the top Build menu select Build Solution. This step is very
similar to the compilation step and the results we also be displayed in the Output window
(Figure 7).

Figure 7: The Output window after linking.

At this point, an executable has been created for our program; we can now run the
program and make sure it works. From the Debug menu, select Start without
Debugging. This will launch the application and you should see the following in the
console box.
Follow the instructions of the application, and press any key to close the
application. Study the application carefully until you have a good understanding of what
each line of code is doing and how the program works. If you have any further questions,
please post in your course forum.

Potrebbero piacerti anche