Cooperative Levels

Because Windows is a multitasking environment, more than one application may be working with a device driver at any one time. Through the use of cooperative levels, DirectX makes sure that each application does not gain access to the device in the wrong way or at the wrong time. Each DirectSound application has a cooperative level that determines the extent to which it is allowed to access the device.

After creating a DirectSound object, you must set the cooperative level for the device with the IDirectSound::SetCooperativeLevel method before you can play sounds.

In Windows® 95 and later and Windows 2000, DirectSound defines four cooperative levels for sound devices: normal, priority, exclusive, and write-primary. These are represented by the values DSSCL_NORMAL, DSSCL_PRIORITY, DSSCL_EXCLUSIVE, and DSSCL_WRITEPRIMARY. Windows CE does not need that level of control, and so the only cooperative level available on Windows CE is DSSCL_NORMAL.

The following C example sets the cooperative level for the DirectSound device initialized at Creating the DirectSound Object. The hwnd parameter is the handle to the application window.

HRESULT hr = lpDirectSound->lpVtbl->SetCooperativeLevel(
        lpDirectSound, hwnd, DSSCL_NORMAL);

Normal Cooperative Level

At the normal cooperative level, the application cannot set the format of the primary sound buffer, write to the primary buffer, or compact the on-board memory of the device. All applications at this cooperative level use a primary buffer format of 44 kHz, stereo sound, and 16-bit samples, so that the device can switch between applications as smoothly as possible. Secondary buffers can be in whatever format required.

For more information, see Access to the Primary Buffer.

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.