HOW TO SET UP YOUR COMPILER FOR DIRECTX AUDIO
Before you can do anything else, you must learn how to properly configure your compiler to build applications that use DirectX Audio. There are two main things you need to do: you need to tell your compiler where it can find the DirectX headers, and where it can find the DirectX libraries. This section will teach you how to do that, assuming you're using Visual C++ version 6. If you're on another compiler, or if you're in Visual Studio .NET, a.k.a. Visual Studio version 7, the concepts are the same, but the actual buttons and menus you have to click will be different.
Global versus Per-Project Configurations
DevStudio has two different configuration sets. There's the global configuration, which applies to all projects you load on your computer, and is kept inside your computer's registry, and there's a per-project configuration, which applies only to the project you have loaded (and is stored inside the DSP project file). The per-project configuration takes precedence over the global configuration (that is, DevStudio first looks for what it needs using the per-project settings, and if it can't find it, it uses the global settings).
Building the Samples in This Book
All of the sample programs in this book assume that you have the DirectX paths set up in your global configuration. (See Figure 2.3.) When you install DirectX, there's an option that lets you automatically add the appropriate paths to DevStudio's configuration. If you didn't select that option, complete the following steps to add the paths.
Select Options from the Tools pull-down menu; then select the Directories tab from the dialog that appears (you may need to scroll the tabs using the scroll buttons on the right).
Select Include Files in the Show Directories For… drop-down box.
Click the button to the left of the red X to create a new entry, and type in the full path to the DirectX include directory. The DirectX SDK installs itself by default at C:/dxsdk, so unless you specified a different location, you should enter C:\dxsdk\include. Do the same thing to enter the path to the samples include directory, normally C:\dxsdk\samples\Multimedia\Common\include.
Drag these two folders up to the top of the list, making DevStudio check these locations before any other locations. This is important, because the default installation of DevStudio has include files for an older DirectX SDK, and grabbing those by mistake will result in errors like "LPDIRECTSOUND8 doesn't exist."
Select Library Files from the Show Directories For drop-down, and follow the same process to add the full path to your DirectX library location (usually C: \dxsdk\lib).
Click OK, then exit DevStudio and re-launch it. DevStudio saves its global configuration when it exits, so if you get in the habit of always exiting after you change the global configuration, you'll protect yourself from having to redo what you changed if (and we all know this is a rare occurrence) DevStudio crashes on you before you exit.

Figure 2.3: The global include path settings.
Congratulations, you should now be all set. If you still get fatal errors (for example, "could not open include file dsound.h: no such file or directory" ), or if you're getting similar link errors, you may not have put in the right paths.
Tip | You don't need to do this to get the samples to run, but if for your own projects you want to change the perproject configuration settings, you can get to them by selecting Settings from the Project menu. The include directories can be found under the C/C++ tab in the Preprocessor category, and the library directories can be found in the Link tab under the Input category. |
Making Your Own Projects
When dealing with DirectX, there are always a few steps you need to complete just to get a bare-bones application up and running. Here, I've written down the steps you need to create the Ch2p1_ToneGenerator workspace.
Tip | The Ch2p1_ToneGenerator workspace is included on your CD-ROM. I provide these steps only as a reference for when you create other projects. |
Select New from the File menu; select the Projects tab, and select the project you want (for example, Win32 Console Application, Win32 Application, or if you're into MFC, MFC AppWizard EXE). Also set up the project name and location.
Work through the wizard that appears. There are no special settings you must have here— pick what you like. For ToneGenerator, I started with a console "Hello World" app.
When the wizard finishes, you should have a program that compiles and runs without error. If you do not, you have a bigger problem—call Microsoft and tell them their stock source code doesn't compile.
Select Settings from the Project menu. On the left side of the dialog, in the Settings For drop-down, select All configurations.
I like to jump to the Precompiled Headers category and select either Not using precompiled headers or Automatic use of precompiled headers. For small projects like this, I think that using precompiled headers through the stdafx.h and stdafx.cpp files are nothing but a pain.
Go to the Link tab and add dxerr8.lib winmm.lib dsound.lib dxguid.lib to the front of the Object/Library modules edit field. These libraries are required for most of the sample programs and most of the DirectX Audio apps you'll create.
Go to the Input category and add the relative path to your DX libraries in the Additional Library Path edit field.
Click OK to dismiss the Project Settings dialog.
Go to your fileview and remove stdafx.cpp and stdafx.h from the project. Also, in all of your source files (you should have just one at this point), remove the line that includes stdafx.h. Because you turned off precompiled headers in step five, these files are no longer needed.
Stdafx.h contained some useful lines that defined WIN32_LEAN_AND_MEAN and included stdio.h. If you want these, you should put them into your main C++ file or one of your own global header files.
Be tidy by deleting stdafx.h and stdafx.cpp from your drive.
Verify that everything still compiles. If not, you probably made a mistake in one of the previous steps, or something "very strange" is going on.