Accessing the Preferred Device ID

The Windows multimedia functions waveInMessage, waveOutMessage, and midiOutMessage can retrieve the device ID of the preferred device. These three functions get the preferred device IDs for wave input, wave output, and MIDI output, respectively. This information is useful to application programs that, for example, allow users to select a device to open from a list of two or more devices. Such an application typically needs to indicate which among the devices in the list is the preferred device.

The preferred device is the device that the user selects through the multimedia control panel, mmsys.cpl. If a Windows multimedia or DirectSound application does not explicitly specify a device, the preferred device is selected by default.

To retrieve the device ID of the current preferred audio device, an application calls the xxxMessage function with the message parameter set to the constant DRVM_MAPPER_PREFERRED_GET.

When calling the waveInMessage, waveOutMessage, or midiOutMessage function with the DRVM_MAPPER_PREFERRED_GET message, specify the value of the device handle as WAVE_MAPPER (for waveInMessage or waveOutMessage) or MIDI_MAPPER (for midiOutMessage) and cast this value to the appropriate handle type: HWAVEIN, HWAVEOUT, or HMIDIOUT. The xxxMessage functions accept this value in place of a valid device handle so that an application can query for the default device ID without first having to open a device. For more information about the xxxMessage functions, see System-Intercepted Device Messages.

The DRVM_MAPPER_PREFERRED_GET message is intercepted by the mapper for the target device (waveIn, waveOut, or midiOut). For information about mappers for wave and MIDI devices, see the Microsoft Windows SDK documentation.