DirectX in Borland C++

Home Up Search X-Zone News Services Book Support Links Feedback Smalltalk MT The Scrapyard FAQ Technical Articles

 

Using DirectX With Borland C++

Written by Michael Lundberg


Edited by Robert Dunlop
Microsoft DirectX MVP

Well , I must admit that I went to hell and back before I get all this to work , but I started with DirectX 3 SDK and they didn't even include Borland compatible libraries so I have to use the IMPLIB program to import them in Borland format.

Initial Setup

The first thing you need is all the libraries and all include files from the DirectX software development kit (The VERY first thing you need is to have DirectX installed , of course).

I use DirectX5 SDK for the moment and there is a separate folder with Borland compatible libraries provided in the package .  One library , DXGuid.lib , was faulty in my package so I have to download a fixed one from internet .( Unfortunately I forgotten where.)  It seem to be a mistake by Microsoft , as usual , and I don't know if all DirectX 5 SDK packages has a faulty DXGuid library .

I have copied all libraries to my BC5 \ libraries folder and all includes to my BC5 \ includes folder to get some order on my already cluttered hard drive. 

Creating a Project

The next thing to do is to start up Borland and make a new project , as usual.  I usually configure my project like this :

Target type : application ( . exe )
Platform     : win 32
Target model : GUI

The only other thing that should be checked is "dynamic" .  Uncheck MFC , OWL and Class libraries.

Referencing Headers and GUID

The first thing to do in the actual program is to include all DirectX include files that you are using. If you use DirectDraw include ddraw.h, if you use Direct3D include d3drm.h and so on.  A typical beginning of my programs looks like this :

#define INITGUID

#define WIN32
#include <stdlib.h>
#include <ddraw.h>
#include <d3drm.h>
#include <math.h>
#include <dinput.h>
#include <ddutil.h>
#include <dsound.h>
#include <dsutil.h>
.
.
.

Linking in the Libraries

All the libraries that you are using must also be added to your project by right clicking in the project window and choose Add Node in the pop up menu.  Then browse your way to the libraries folder , in my example BC5 \ libraries and click on the library you want to add, ddraw.lib, d3drm.lib, dsound.lib or whatever.  If you don't intend to use any 3D there's no need to add any of the 3D libraries of course.

One special thing is when you want to use DirectInput.  After including dinput.h and added dinput.lib you must also add DXGuid.lib to your project.  It has something to do with GUIDs or something .:-|  And that should do it .Now its time to hack something beautiful and run the whole thing .

Compiling the Samples

It is much harder to compile the examples that comes with the package.  Many examples uses functions in many external programs.  All DirectDraw examples , for example :-) , uses functions in the ddutil.cpp file stored elsewhere in the package.  To run those examples create a project like above.  You also need to check if there is a resource file in the sample folder , in that case choose Advanced in the Project menu and check the .rc button.  After that you must include the ddutil.h file at the beginning of your code and add ddutil.cpp using Add Node , as explained above.  To run the samples that uses sound you must also add dsutil.h to your code and dsutil.cpp to your project.  PUH!

It becomes even more difficult  if you want to run the 3D samples because they use even more external programs . One tip is to check the top of the sample program to see which files that are included .If you don't add all those programs and libraries correct the famous  UES (Unresolved External Syndrome ) happens , and thats not funny.

Setting up the Floating Point Unit for Direct3D

If you want to use Direct3D the following line must be added to your program, to override the floating point exception handler:

int _matherr(struct _exception *e){e; return 1;}

In addition, you will need to add the following line to your initialization routine prior to starting Direct3D:

_control87(MCW_EM,MCW_EM);

It has something to do with Borland error routines , don't ask why , just put it in somewhere ( I'm happy as long as things works and I never ask why they work).

 

This site, created by DirectX MVP Robert Dunlop and aided by the work of other volunteers, provides a free on-line resource for DirectX programmers.

Special thanks to WWW.MVPS.ORG, for providing a permanent home for this site.

Visitors Since 1/1/2000: Hit Counter
Last updated: 11/15/01.