Obtaining the IDirectSound3DBuffer Interface

To obtain a pointer to an IDirectSound3DBuffer interface, you must first create a secondary 3-D sound buffer. Do this by using the IDirectSound::CreateSoundBuffer method, specifying the DSBCAPS_CTRL3D flag in the dwFlags member of the DSBUFFERDESC structure parameter. Then, use the IDirectSoundBuffer::QueryInterface method on the resulting buffer to obtain a pointer to an IDirectSound3DBuffer interface for that buffer.

The following example calls the QueryInterface method with the C++ syntax:

// LPDIRECTSOUNDBUFFER lpDsbSecondary;
// The buffer has been created with DSBCAPS_CTRL3D. 
LPDIRECTSOUND3DBUFFER lpDs3dBuffer;

HRESULT hr = lpDsbSecondary->QueryInterface(IID_IDirectSound3DBuffer, 
                                            &lpDs3dBuffer); 
if (SUCCEEDED(hr)) 
  { 
  // Set 3-D parameters of this sound. 
    . 
    . 
    . 
  } 
 

Note  Pan control conflicts with 3-D processing. If both DSBCAPS_CTRL3D and DSBCAPS_CTRLPAN are specified when the buffer is created, DirectSound returns an error.