Reading Wave Data from a Resource

The DirectSound API does not include methods for reading a wave from a resource. However, there are helper functions in Dsutil.c, which you will find in the Sdk\Samples\Misc folder.

To store wave sounds in an executable or DLL, import your wave files as resources and give them string names. Note that Dsutil.c expects these resources to be of type "WAV." If you are using Microsoft Visual C++®, imported wave files are turned into resources of type "WAVE." You must either change this nomenclature to "WAV" by editing the resource file, or else modify the assignment of c_szWAV in Dsutil.c so that the FindResource function is looking for "WAVE" resources.

You may also want to modify Dsutil.c so that the DSLoadSoundBuffer function sets only the appropriate control flags.

To create a static buffer and load the sound into it, simply pass the IDirectSound interface pointer and the name of the resource to the DSLoadSoundBuffer function. If successful, the function returns a pointer to the buffer. Here's a sample call, where lpds is the pointer to the IDirectSound interface:

#include "dsutil.h"

LPDIRECTSOUNDBUFFER lpdsbFootstep;

lpdsbFootstep = DSLoadSoundBuffer(lpds, "FOOTSTEP");

if (lpdsbFootstep == NULL)

{

// Failure

}