Home | Site Map
Sunlight

DirectX and .NET

Update

This tutorial explores the interworking of DirectX 8 with the .NET Framework. After the writing of this article, some details of DirectX 9 have appeared.

DirectX 9 will include 'Managed DirectX'. This appears to be a C++ .NET wrapper around the DirectX classes. This should sound somewhat familiar... Microsoft will produce a more complete implementation than I have the time to produce, so I will wait for DirectX 9 before the next version of this tutorial.

First details of DirectX 9 indicate that it will include managed wrappers for Direct3D 9, DirectDraw 7, DirectSound, DirectPlay and DirectInput 8. This means no DirectShow and no DirectMusic. It may seem odd to you that Microsoft would support DirectDraw and DirectSound over the latter two; it certainly seems odd to me.

Please note that the above observations relate to a beta release of DirectX 9; there is no guarantee that they will apply to the released version. Microsoft may, of course, decide to let their .NET framework commit client-side suicide by not releasing Managed DirectX at all.

The techniques described in this tutorial will continue to work with the new version of DirectX. DirectX 9 is expected in late October.

Introduction

In this tutorial, we will investigate the interoperation of DirectX with the Microsoft .NET Framework. We will use the knowledge of DirectX gained in the DirectX tutorial to build a DirectX .NET wrapper, then use that in C# and Visual Basic.NET applications.

Existing .NET DirectX samples use the DirectX Visual Basic type library. While this is adequate for some purposes, it makes working with vertex buffers difficult, and generally lacks the flexibility offered by the COM API. For this reason, and for the reason that it needs as much description as anything else, we will create a C++.NET class library wrapper for the parts of DirectX we plan to use.

We will first explore the class hierarchy. We will then go on to implement each of the classes in the hierarchy, learning about C++.NET interoperation concepts as we go. Finally, we will explore the fruits of our exploration and class library by building two sample applications using the class library: a version of the test program in the DirectX tutorial, and a 'Snake'-type game.

For this tutorial, you will need a working knowledge of C++.NET, C#.NET or VB.NET, as well as an understanding of the concepts underlying .NET. This is not a general .NET tutorial; these can be found in the .NET Framework SDK, as well as plenty of places on the Internet. You will also need to have a working knowledge of the various components of DirectX. A DirectX tutorial can be found here.

You will also need a .NET compiler. Currently, these are supplied with the .NET Framework SDK. I strongly recommend using Microsoft Visual Studio .NET on Windows 2000 or XP. The samples can also be compiled using the .NET compilers alone, on Windows 2000, XP or Windows 98/ME.

To explore the class library implementation, you will need a thorough knowledge of C++, and of DirectX. If you do not have this knowledge, you can skip the class library implementation chapters and go directly from the hierarchy to the descriptions of the sample applications.

Downloads

Table of Contents