IMMDeviceEnumerator::EnumAudioEndpoints Method

The EnumAudioEndpoints method generates a collection of audio endpoint devices that meet the specified criteria.

Syntax

public:
HRESULT EnumAudioEndpoints(
         EDataFlow dataFlow,
         DWORD dwStateMask,
         IMMDeviceCollection **ppDevices
)  

Parameters

dataFlow
Type: EDataFlow 

[in]

The data-flow direction for the endpoint devices in the collection. The caller should set this parameter to one of the following EDataFlow enumeration values:

eRender

eCapture

eAll

If the caller specifies eAll, the method includes both rendering and capture endpoints in the collection.

dwStateMask
Type: DWORD 

[in]

The state or states of the endpoints that are to be included in the collection. The caller should set this parameter to the bitwise OR of one or more of the following constants.

Constant Value Description
DEVICE_STATE_ACTIVE 0x00000001 The audio endpoint device is active. That is, the audio adapter that connects to the endpoint device is present and enabled. In addition, if the endpoint device plugs into a jack on the adapter, then the endpoint device is plugged in.
DEVICE_STATE_DISABLED 0x00000002 The audio endpoint device is disabled. The user has disabled the device in the Windows multimedia control panel, Mmsys.cpl.
DEVICE_STATE_NOTPRESENT 0x00000004 The audio endpoint device is not present because the audio adapter that connects to the endpoint device has been removed from the system, or the user has disabled the adapter device in Device Manager.
DEVICE_STATE_UNPLUGGED 0x00000008 The audio endpoint device is unplugged. The audio adapter that contains the jack for the endpoint device is present and enabled, but the endpoint device is not plugged into the jack. Only a device with jack-presence detection can be in this state.
DEVICE_STATEMASK_ALL 0x0000000F Includes audio endpoint devices in all states—active, disabled, not present, and unplugged.

For example, if the caller sets the dwStateMask parameter to DEVICE_STATE_ACTIVE | DEVICE_STATE_UNPLUGGED, the method includes endpoints that are either active or unplugged from their jacks, but excludes endpoints that are on audio adapters that have been disabled or are not present. To include all endpoints, regardless of state, set dwStateMask = DEVICE_STATEMASK_ALL.

ppDevices
Type: IMMDeviceCollection **

[out]

Pointer to a pointer variable into which the method writes the address of the IMMDeviceCollection interface of the device-collection object. Through this method, the caller obtains a counted reference to the interface. The caller is responsible for releasing the interface, when it is no longer needed, by calling the interface’s Release method. If the EnumAudioEndpoints call fails, ppDevices* is **NULL.

Return value

Type: HRESULT 

If the method succeeds, it returns S_OK. If it fails, possible return codes include, but are not limited to, the values shown in the following table.

Return codes
Return code Description
E_POINTER Parameter ppDevices is NULL.
E_INVALIDARG Parameter dataFlow or dwStateMask is out of range.
E_OUTOFMEMORY Out of memory.

Refer to WASAPI error codes.

Remarks

For example, the following call enumerates all audio-rendering endpoint devices that are currently active (present and not disabled):

Example

  hr = pDevEnum->EnumAudioEndpoints(
                   eRender, DEVICE_STATE_ACTIVE,
                   &pEndpoints);  

In the preceding code fragment, variable hr is of type HRESULT, pDevEnum is a pointer to an IMMDeviceEnumerator interface, and pEndpoints is a pointer to an IMMDeviceCollection interface.

Requirements

Header: Declared in mmdeviceapi.h.

Library: Use MMDevApi.lib.

See also

IMMDeviceEnumerator

IMMDeviceEnumerator Members