Home | Site Map
Sunlight

Building the Library

Introduction

This chapter will explain how to build the DirectX.NET class library. It will also explain the precompiled header implementations in DirectX .NET.

Building the Project

Building from the Visual Studio .NET Environment

Before you can build these files from within Visual Studio .NET, you need one other thing:

In Visual C++.NET, building the project is as simple as loading the project file supplied in the .ZIP file.

Building from the Command Line

Before you can build these files from the command line, you need a couple of things:

  • The .NET framework SDK (unless you already have Visual C++.NET), which is about 130Mb.
  • The Microsoft Platform SDK. You need at least the Core SDK (unless you already have Visual C++.NET) and the DirectX SDK. You only require the "Build Environment" for each of these. These add up to about 40Mb.

If you are building these files from the command line, enter the following command line:

cl /Zc:wchar_t,forScope /clr /FeSunlight.DirectX.dll /LD *.cpp

The flags are:

  • the /Zc flags enforce wchar_t as a separate type and the new 'for' scoping rules;
  • /clr specifies a .NET assembly target;
  • /Fe defines the executable file name;
  • /LD specifies a DLL target.

If you get link errors about .h or .lib files, make sure your INCLUDE and LIB environment variables are set appropriately. Typically, you want something like

set INCLUDE=C:\Program Files\Microsoft.NET\FrameworkSDK\Include;
C:\Program Files\Microsoft Visual Studio .NET\Vc7\include
set LIB=C:\Program Files\Microsoft.NET\FrameworkSDK\Lib;
C:\Program Files\Microsoft Visual Studio .NET\Vc7\lib

Note that both of these are on one line.

Precompiled Headers

Before we begin with the implementation, we need a few declarations. Visual C++.NET adds two files to your project when you create a new C++ class library, 'stdafx.h' and 'stdafx.cpp'. These are part of the precompiled headers, which compile the header file information into a .PCH file once. This avoids the headers having to be recompiled the next time you compile your source code.

The headers in stdafx.h are:
#using <mscorlib.dll>
#using <system.dll>
#using <system.drawing.dll>
#using <system.windows.forms.dll>

#define DIRECTINPUT_VERSION         0x0800

#include <d3d8.h>
#include <d3dx8.h>
#include <dinput.h>
#include <dmusicc.h>
#include <dmusici.h>
#include <dshow.h>
#include <malloc.h>
#include <shlwapi.h>
#include <string.h>
#include <tchar.h>

Note the use of #using to bring in the Microsoft core libraries, and the System, System.Drawing and System.Windows.Forms libraries, which implement their respective namespaces.

In the next section, we will introduce the basic graphics classes.