Obtaining the IDirectSound3DListener Interface

To obtain a pointer to an IDirectSound3DListener interface, you must first create a primary 3-D sound buffer. Do this by using the IDirectSound::CreateSoundBuffer method, specifying the DSBCAPS_CTRL3D and DSBCAPS_PRIMARYBUFFER flags in the dwFlags member of the accompanying DSBUFFERDESC structure. Then, use the IDirectSoundBuffer::QueryInterface method on the resulting buffer to obtain a pointer to an IDirectSound3DListener interface for that buffer, as shown in the following example with C++ syntax:

// LPDIRECTSOUNDBUFFER lpDsbPrimary;
// The buffer has been created with DSBCAPS_CTRL3D. 
LPDIRECTSOUND3DLISTENER lpDs3dListener;

HRESULT hr = lpDsbPrimary->QueryInterface(IID_IDirectSound3DListener, 
                                          &lpDs3dListener); 
 
if (SUCCEEDED(hr)) 
  { 
  // Perform 3-D operations. 
  . 
  . 
  . 
  }