DirectX SDK

DirectSound.SetCooperativeLevel

The DirectSound.SetCooperativeLevel method sets the cooperative level of the application for this sound device.

object.SetCooperativeLevel(hwnd As Long, _
    level As CONST_DSSCLFLAGS)

Parameters

object
Object expression that resolves to a DirectSound object.
hwnd
Window handle to the application. See Remarks.
level
Requested priority level. Specify one of the following constants of the CONST_DSSCLFLAGS enumeration:
DSSCL_EXCLUSIVE
Sets the application to the exclusive level. When it has the input focus, the application will be the only one audible (sounds from applications with the DSBCAPS_GLOBALFOCUS flag set will be muted). With this level, it also has all the privileges of the DSSCL_PRIORITY level. DirectSound will restore the hardware format, as specified by the most recent call to the DirectSoundBuffer.SetFormat method, once the application gains the input focus. (Note that DirectSound will always restore the wave format no matter what priority level is set.)
DSSCL_NORMAL
Sets the application to a fully cooperative status. This level has the smoothest multitasking and resource-sharing behavior, but because it does not allow the primary buffer format to change, output is restricted to the default 8-bit format.
DSSCL_PRIORITY
Sets the application to the priority level. Applications with this cooperative level can call the DirectSoundBuffer.SetFormat method.
DSSCL_WRITEPRIMARY
This is the highest priority level. The application has write access to the primary sound buffers. No secondary sound buffers can be played. This level cannot be set if the DirectSound driver is being emulated for the device; that is, if the DirectSound.GetCaps method returns the DSCAPS_EMULDRIVER flag in the DSCAPS type.

Error Codes

If the method fails, an error is raised and Err.Number may be one of the following error values:

DSERR_ALLOCATED
DSERR_INVALIDPARAM
DSERR_UNINITIALIZED
DSERR_UNSUPPORTED

Remarks

The application must set the cooperative level by calling this method before its buffers can be played. The recommended cooperative level is DSSCL_PRIORITY; use other priority levels when necessary.

The hwnd parameter should be the top-level application window handle. If you are also using DirectDraw, it must be the same handle passed to the DirectDraw7.SetCooperativeLevel method.

See Also

DirectSoundBuffer.GetFormat, DirectSoundBuffer.GetVolume, DirectSoundBuffer.Play, DirectSoundBuffer.Restore, DirectSoundBuffer.SetFormat