Visual Studio Tutorial (1/1)

Introduction

In this tutorial we show how to create a simple 64-bit application with Visual Studio 2013. By default the Visual Studio projects are 32-bit applications. Changing the settings so that they are 64-bit is easy and there isn't anything really difficult on this page but if you've never done it before it helps to see how it is done once in detail.

A 64-bit Console Application

Let's create a very simple 64-bit console application. We create a console application called "ConsoleApp64bit" using the "Win32 Console Application" template as shown on Figure 1. We keep the default project settings.

Project Creation Wizard
Figure 1: Project Creation Wizard

We modify the generated ConsoleApp64bit.cpp file to print the size of a pointer. This will indicate whether the application we built is 32-bit or 64-bit as the size of a pointer will be 4 bytes in a 32-bit application and 8 bytes in a 64-bit one. The ConsoleApp64bit.cpp file is shown below.

File: ConsoleApp64bit.cpp
// ConsoleApp64bit.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
    std::cout << "The pointer size is " << sizeof(void*) << " bytes" << std::endl;
    return 0;
}

If we compile and run the program now we get the following output.

32-bit program output
The pointer size is 4 bytes
Press any key to continue . . .

Let's now change the settings to build a 64-bit application.

When doing the change described below we ran into a strange issue that seems related to source control. The configuration changes couldn't be made until we opened all files for edit. You may want to keep that in mind if for some reason you can't open some of the dialogs shown below

The target platform is part of the build configuration. To change it we open the Configuration Manager as shown on figures 2 and 3.

Opening the Configuration Manager
Figure 2: Opening the Configuration Manager


Configuration Manager Dialog
Figure 3: Configuration Manager Dialog

All we need to do now is to switch the platform from Win32 to x64. In this example we will add a 64-bit configuration to the existing 32-bit ones so it will still be possible to build the application as a 32-bit application by switching to the Win32 configuration. To add a 64-bit configuration we use the <New...> menu item as shown in Figure 4.

Configuration Manager Dialog with New... selected
Figure 4: Configuration Manager Dialog with New... selected

The <New...> menu item opens the dialog shown on Figure 5. We select the x64 platform.

New Project Platform Dialog
Figure 5: New Project Platform Dialog

After these changes the Configuration Manager looks like what is shown on Figure 6.

Configuration Manager dialog after the changes
Figure 6: Configuration Manager dialog after the changes

If we now close the Configuration Manager and run the application we get the output shown below.

64-bit program output
The pointer size is 8 bytes
Press any key to continue . . .

The size of a pointer is now 8 bytes which shows that we are now running a 64-bit application.


Copyright(c) 2006-2015 Xavier Leclercq | Privacy policy

Home
Contact Us
Search