The OnDeviceStateChanged method indicates that the state of an audio endpoint device has changed.
public:
HRESULT OnDeviceStateChanged(
LPCWSTR pwstrDeviceId,
DWORD dwNewState
)
pwstrDeviceId
Type: LPCWSTR
[in]
Pointer to the endpoint ID string that identifies the audio endpoint device. This parameter points to a null-terminated, wide-character string containing the endpoint ID. The string remains valid for the duration of the call.
dwNewState
Type: DWORD
[in]
Specifies the new state of the endpoint device. The value of this parameter is one 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. |
Type: HRESULT
If the method succeeds, it returns S_OK. If it fails, it returns an error code.
Refer to WASAPI error codes.
For a code example that implements the OnDeviceStateChanged method, see Device Events.
Header: Declared in mmdeviceapi.h.
Library: Use MMDevApi.lib.