DirectX 7 with BCBuilder 4

By: Andrew Ames

Abstract: The purpose of this document is to provide information that will aid in setting up Borland C++ Builder 4 projects that use DirectX 7 (specifically, Direct3D).

 
Configuring DirectX 7 with C++Builder 4

The purpose of this document is to provide information that will aid in setting up Borland C++ Builder 4 for use with DirectX 7 (specifically, Direct3D). This document will take you step-by-step through building the Direct3D Immediate Mode sample programs. The DX SDK must be installed. 

It is available for download at  http://www.microsoft.com/downloads/release.asp?ReleaseID=12253 

Refer to  http://www.microsft.com/directx  for general information. 

All of the D3D IM samples are located in "[MSDX7]samplesMultimediaD3DIM". This path will be referred to as [D3DSAMP]. These samples rely on a static library called d3dframe. This library provides a consistant interface for all the D3D samples and can be useful while learning how to use the D3D API. The headers for this library are located in "[D3DSAMP]include", the Borland-compatible LIB is located in "[D3DSAMP]lib", and the source code for this library is located in "[D3DSAMP]srcd3dframe". The pre-built LIB was built with BC 5.02 and is not compatible with BCB 4. So, we must rebuild this library. To rebuild the samples with Builder, it is helpful to create a seperate directory tree for the samples. Here's the directory structure used throughout the rest of this document: 

- Borland DX7
      - bin
      - include
      - lib
      - src
            - Bd3dframe 

From now on, the "Borland DX7" folder will be referred to as [BDX7]. This directory structure mimics that of the D3DIM samples structure. The compiled exes will be in "bin", the d3dframe LIB headers will be in "include", the BCB-compatible LIB will be in "lib", and the source for all the samples as well as d3dframe will be in "src". 

1) Copy all header files from "[D3DSAMP]include" to "[BDX7]include". Copy all source files from "[D3DSAMP]srcd3dframe" to "[BDX7]srcBd3dframe". 

2) Open BCB 4 and create a new Library (File | New, then double-click Library). Save the project as "[BDX7]srcBd3dframeBd3dframe.bpr". 

3) Add all source files in "[BDX7]srcBd3dframeBd3dframe" to the library (excluding Bd3dframe.cpp, which is the library itself). 

4) Go to Project | Options and add the following to the "include" paths: "[MSDX7]include" - Note this is the root of the DX SDK. "[BDX7]include" 

Make sure the DX headers are searched before the BCB headers. BCB ships with DX 5 headers and import LIBs. Compiling will fail if the older headers are used. 

5) Add the following to the Final Output path in Project | Options: "[BDX7]lib" 

6) Attempting to build the library will give several "Undefined symbol 'i'" errors. Simply place a "DWORD" type declaration in front of 'i' in each of these cases. 

7) Eventually, you'll find "Call to undefined function 'sinf'" errors. Perform a Search | Replace on all of these to convert them to sin...(lose the 'f'). This happens with cosf, acosf, and sqrtf in many places as well. MS decided they weren't going to stick with ANSI C library routines. 

8) At this point, we should have a successful Build of Bd3dframe.lib. 

Now we can go ahead and build one of the samples. We'll create a project group to hold the Bd3dframe library and the samples. 

1) Create folder "[BDX7]srcBend". Copy the following files from"[D3DSAMP]srcBend" to this folder: "resource.h", "bend.cpp", "directx.ico", and "winmain.rc". 

2) Create a new project group and save it as "[BDX7]srcBorland DX7.bpg". Add the Bd3dframe project to this group. 

3) Create a new project using a "Console Wizard | GUI" application type. Before saving the new project, copy the text from Bend.cpp into the default cpp file created for the new project (probably called "Project1.cpp". Make sure you do not delete the condefs.h include file. 

4) Save the new project as "[BDX7]srcBendBend.bpr". 

5) Add "[BDX7]srcBendwinmain.rc", "[BDX7]libBD3DFrame.lib", and "[MSDX7]libBorlandddraw.lib" to the Bend project. 

14) To acquire access to the DX GUIDs, we need to do one of two things. Add the following line to the top of Bend.cpp before any includes: "#define INITGUID". Or, we can add "[MSDX7]libBorlanddxguid.lib" to the Bend project. 

15) Go to Project | Options and add "[MSDX7]include" and "[BDX7]include" to the include path. Make sure they're searched before the BCB include path. Add "[BDX7]bin" to the final output path. 

16) Build and run Bend.exe. All other D3D samples can be built similarly. 

One final note regarding DX 7: the D3DX Utility library supplied with the SDK will not work with Builder because it is a static library and MS is reserving all rights to the source. They have not provided any Borland-compatible version. 


Server Response from: ETNASC03