Borland C++ 5.0 Setup For DirectX 5.0

By Bruce Veazie

I've seen quite a few questions and answers with regard to compiling and running DirectX 5.0 samples with Borland C++ 5.0. It took me a while to get things running smoothly so I thought I'd share some lessons learned. It is, after all, an uphill battle to use Microsoft files and documentation with Borland compilers.

First - you have to have the Borland compatible libraries to do anything. When you run dx5eng.exe to install dx5, it creates a dx5sdk directory with a bunch of subdirectories, etc. After you run the setup* in the dx5sdk directory, you'll have a dxsdk directory and subdirectories which looks very much like the dx5sdk directory and subdirectories. There's one very important difference! No Borland compatible lib files in the dxsdk. You need to create a subdirectory \dxsdk\sdk\lib\Borland and copy into it all the files from dx5sdk\sdk\lib\Borland. Must've been an oversight in Microsoft's setup. So, if don't have the Borland libs and you don't have the dx5sdk Borland lib directory any more, you need to run dx5eng.exe again and copy the lib files.

Note: If you haven't run the setup program in the dx5sdk, you haven't completed installation of the dx5 SDK! Running the setup program in the dx5sdk directory will create another directory tree rooted at dxsdk (vs. dx5sdk) and expand and copy files from the dx5sdk directory into it. If you have some of your own stuff in the dx5sdk directories make sure you transfer whatever you want to use into the newly created dxsdk directory and subdirectories. For sure, copy the Borland compatible libraries as described above. Following the setup, you can delete the dx5sdk directory (and all its subdirectories) to avoid a lot of extra disk space taken up with duplicate files.

BTW, I copied all the DirectX Borland libraries in dxsdk\sdk\lib\Borland to my \bc5\lib directory and all the files in \dxsdk\sdk\inc to my \bc5\include directory.

Problem: DirectX 5.0 programs run OK when launched from the IDE but bomb on errors when run under Windows directly.

Try adding a floating point error handler as recommended in the help documentation [see below] under D3D Immediate Mode/Troubleshooting/Borland Floating-Point Initialization. DirectX library error handlers and Borland default error handlers are apparently incompatible. The errors I encountered that occurred only outside the IDE disappeared when I added the error handler (actually an error disabler). Add code similar (or identical if you want) to that below to one of the modules in your project. Somewhere in the initialization (WinMain, before the message loop, is a good choice), before any DirectX functions are called, call initfp(). That's it.

--- example from help documentation

// Borland floating point initialization
#include <MATH.H>
#include <FLOAT.H>

void initfp(void)
    // disable floating point exceptions

int _matherr(struct _exception  *e)
    e;               // dummy reference to catch the warning
    return 1;        // error has been handled
--- end of example

As a personal preference, I added the above to the rmmain.cpp file in samples\misc since that file is common to several of the samples.

Problem: when a sample is compiled, link errors of the type "Unresolved external.." keep coming up.

Not all the files (cpp, c, rc and lib) that need to be a part of the project have been added to the project. See the description below on how to setup a BC5 project for samples. I haven't tried compiling all the samples. But I've tried a lot of them and I'm consistently successful with compiles and runs using the guidelines below.

My suggestions for setting up a BC5 project file for a dx5 sample from the SDK:

  1. Make sure you have the Borland .lib files from the pre-setup SDK [see above]. If you don't have the Borland lib files, you may as well stop right now.
  2. Look in the sample directory you're interested in and note whether there the sample is C or CPP and if there is a companion .rc for the sample. I don't use the SDK .def files at all. Borland's defaults seem to be fine. For example, in the samples\egg directory you'll see egg.c and egg.def but no egg.rc.
  3. In BC5, create a new project. In the project creation dialog, browse to the sample subdirectory and give your .ide file the name of the sample C or CPP file. Example: browse to c:\dxsdk\sdk\samples\egg and name the new project egg.ide.
  4. Disable the Frameworks Owl and Class library links [ uncheck the boxes ].
  5. Click "Advanced.." and select C or CPP node as appropriate for the sample file (that already exists), uncheck ".def" and check ".rc" if there's an rc file for the sample, else uncheck ".rc". I suggest disabling ".def" files for ALL the samples. Example: for the "egg" sample, ".c" would be checked [which unchecks ".cpp"] and ".def" and ".rc" would be unchecked.
  6. Make sure the Platform option is Win32 and the target model is GUI.
  7. Hit the OK button to create the project. Example: for "egg", in the project window should be just the project "egg.exe" with an "egg.c" node.
  8. Under the IDE menu Options/Project/Compiler/Precompiled headers - select "Do not generate or use." If you try, you'll just get warnings that it can't be done anyway 'cause some of the DirectX headers have initialized data.
  9. Under Options/Project/Directories - Include file directories - add c:\dxsdk\sdk\inc and c:\dxsdk\sdk\samples\misc (or whereever your equivalents are) just on general principles. You'll almost always need \inc and you'll need \misc often.
  10. Open "makefile" in the project directory (it's a text file) and examine it to see what other files and libraries you'll need for the project. If you're not familiar with makefiles, look for ".cpp",".c",".rc" and ".lib" entries in the file.

    For example, in "makefile" in the samples\egg directory you'll see a line "proj=egg". You can substitute "egg" whereever you see "$(proj)" in the file. A couple lines below, in the line that begins "$(OBJ_DIR)", you'll see "$(proj).c" so you know you need "egg.c" (which you should already have) for the project. In the next paragraphs there's "..\misc\rmmain.cpp", "..\misc\rmerror.c" and "..\misc\rmmain.rc". All those will have to be added to the project. Below that, in the paragraph that contains "$(link)" you'll see "$(guilibs) ddraw.lib d3drm.lib". Those 2 libraries will need to be added to the project.

    In the step below, assume you need to add rmmain.cpp, rmerror.c, rmmain.rc, ddraw.lib and d3drm.lib to the project.

  11. In the project window, right-click on the project node (the .exe file) and select "Add Node".
  12. In the dialog box that follows, browse to the samples\misc directory and singly or all at once, whatever works for you, select rmerror.c, rmmain.cpp and rmmain.rc. Click "Open" which will add them to the project.
  13. In the project window, right-click (left-handers left-click) on the project node and select "Add Node" again. Set the file type selector to "*.lib." Browse to the directory where you have your Borland compatible DirectX libraries and select "ddraw.lib" and "d3drm.lib". Click "Open" to add them to the project.
  14. Now, in the IDE, click on the "Make project" button. You'll get a slew of warnings but shouldn't get any errors. The warnings should be mostly of the type "arguments not used" and "possibly incorrect assignments." However, the sample should compile and run.

Copyright 1997 Bruce J. Veazie
Reprinted with permission.

Discuss this article in the forums

Date this article was posted to 7/25/1999
(Note that this date does not necessarily correspond to the date the article was written)

See Also:

© 1999-2011 All rights reserved. Terms of Use Privacy Policy
Comments? Questions? Feedback? Click here!