Setting Up Visual Studio .NET 2003

Before you can start programming with DirectX, you need to setup your IDE so it can find all the DirectX files.

Step 1

First, create a new Win32 project.

Step 2

Just click Finish here.

Step 3

Go up to the menu bar and hit Tools > Options.

Step 4

In the Options dialog, click on the Project folder in the menu tree on the left. Then click VC++ Directories. This is where we can tell Visual Studio where to find the DirectX libraries and header files. In the top right corner of the Options dialog is the “Show directories for:” drop down menu. First select “Include files” so we can set the directory of the DirectX header files. Installing the DirectX SDK should have put in the directory automatically, but if it didn’t, you’ll need to add the Include directory yourself. Make sure the directory ends up at the top of the list as shown in the picture. This is to ensure that Visual Studio uses the latest SDK instead of the SDK that is installed with Visual Studio.

Step 5

Next, set the DirectX library directory. This is the same process as setting the Include directory except you select “Library files” from the drop down menu. Don’t forget to move it to the top of the list. After this, click OK.

Step 6

Go up to the menu bar again and click Project > “Your project name here” Properties.

Step 7

The IDE knows where to find the DirectX files, but you need to tell Visual Studio that the current project is going to use the DirectX libraries. In the Project Properties dialog, select Linker > Input from the tree on the left. In “Additional Dependencies” you need to add all the library files that the project will be using. To get started, add “dxerr9.lib dxguid.lib d3dx9d.lib d3d9.lib dinput8.lib winmm.lib comctl32.lib“.

// stdafx.h : include file for standard system include files, 
// or project specific include files that are used frequently, but 
// are changed infrequently 
//
#pragma once

// Exclude rarely-used stuff from Windows headers 
#define WIN32_LEAN_AND_MEAN

#define SAFE_RELEASE(x) if( x ) { (x)->Release(); (x) = NULL; } 
#define SAFE_DELETE(x) if( x ) { delete(x); (x) = NULL; } 
#define SAFE_DELETE_ARRAY(x) if( x ) { delete [] (x); (x) = NULL; }

// Windows Header Files: 
#include 

// C RunTime Header Files 
#include  
#include  
#include  
#include  
#include 

// DirectX Header Files 
#include  
#include 

And finally, you need to include the DirectX headers (d3d9.h and d3dx9.h) in the source code. By default, Visual Studio uses precompiled headers. Therefore, add the includes into the stdafx.h file. This is also a nice place to define macros that you might want to use throughout your program. With precompiled headers, you need to include stdafx.h in every file.

After these steps, Visual Studio should all be ready to use DirectX.