> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XUserGetDefaultAudioEndpointUtf16

> XUserGetDefaultAudioEndpointUtf16

# XUserGetDefaultAudioEndpointUtf16

Retrieves the default audio endpoint for a specific user.

## Syntax

```cpp theme={null}
HRESULT XUserGetDefaultAudioEndpointUtf16(  
         XUserLocalId user,  
         XUserDefaultAudioEndpointKind defaultAudioEndpointKind,  
         size_t endpointIdUtf16Count,  
         wchar_t* endpointIdUtf16,  
         size_t* endpointIdUtf16Used  
)  
```

### Parameters

*user*   \
Type: [XUserLocalId](/reference/system/xuser/structs/xuserlocalid)\
The local ID of the user to get the default audio endpoint for.

*defaultAudioEndpointKind*   \
Type: [XUserDefaultAudioEndpointKind](/reference/system/xuser/enums/xuserdefaultaudioendpointkind)\
An enumeration value that specifies whether the user's default audio endpoint renders or captures audio.

*endpointIdUtf16Count*   \
Type: size\_t\
The wchar\_t count of the buffer that the *endpointIdUtf16* parameter points to. Pass **XUserAudioEndpointMaxUtf16Count**.

*endpointIdUtf16*   \_Out\_writes\_to\_(endpointIdUtf16Count,*endpointIdUtf16Used)\
Type: wchar\_t*\
Contains the ID of the user's default audio endpoint.

*endpointIdUtf16Used*   \_Out\_opt\_\
Type: size\_t\*

Contains the actual wchar\_t count of the ID that the *endpointIdUtf16* parameter returns.

### Return value

Type: HRESULT

Returns S\_OK if successful; otherwise, returns an error code.
For a list of error codes, see [Error Codes](/reference/errorcodes).

## Remarks

<Note>This function isn't safe to call on a time-sensitive thread. For more information, see [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads).</Note>

The XUserGetDefaultAudioEndpointUtf16 function takes an [XUserDefaultAudioEndpointKind](/reference/system/xuser/enums/xuserdefaultaudioendpointkind) enumeration as an argument.

The [XUserDefaultAudioEndpointUtf16ChangedCallback](/reference/system/xuser/functions/xuserdefaultaudioendpointutf16changedcallback) callback function invokes when the default audio endpoint for a specific user changes.

To register to receive a callback when the default audio endpoint changes, call [XUserRegisterForDefaultAudioEndpointUtf16Changed](/reference/system/xuser/functions/xuserregisterfordefaultaudioendpointutf16changed).

To un-register to receive a callback when the default audio endpoint changes, call [XUserUnregisterForDefaultAudioEndpointUtf16Changed](/reference/system/xuser/functions/xuserunregisterfordefaultaudioendpointutf16changed).

The following example demonstrates how to retrieve the default audio endpoint for a user.

```cpp theme={null}
HRESULT GetAudioDeviceAssociation(
    IMMDeviceEnumerator* audioDeviceEnumerator,
    XUserLocalId user,
    XUserDefaultAudioEndpointKind defaultAudioEndpointKind,
    _Outptr_result_maybenull_ IMMDevice** endpoint)
{
    wchar_t audioDeviceId[XUserAudioEndpointMaxUtf16Count];
    RETURN_IF_FAILED_WITH_EXPECTED(XUserGetDefaultAudioEndpointUtf16(user, defaultAudioEndpointKind, std::size(audioDeviceId), audioDeviceId, nullptr), E_NOTFOUND);

    return audioDeviceEnumerator->GetDevice(audioDeviceId, endpoint);
}

HRESULT GetAudioAssociations()
{
    Mwrl::ComPtr<IMMDeviceEnumerator> audioDeviceEnumerator;

    RETURN_IF_FAILED(CoCreateInstance(
        __uuidof(MMDeviceEnumerator),
        nullptr,
        CLSCTX_ALL,
        __uuidof(IMMDeviceEnumerator),
        (void**)&audioDeviceEnumerator));

    XUserLocalId userLocalId;
    RETURN_IF_FAILED(XUserGetLocalId(_handle.get(), &userLocalId));

    {
        wil::unique_cotaskmem_string id;
        Mwrl::ComPtr<IMMDevice> device;
        if (SUCCEEDED(GetAudioDeviceAssociation(audioDeviceEnumerator.Get(), userLocalId, XUserDefaultAudioEndpointKind::CommunicationRender, &device)))
        {
            RETURN_IF_FAILED(device->GetId(&id));
        }
        appLog.AddLog("Preferred render communication device id: %S\n", id.get());
    }

    {
        wil::unique_cotaskmem_string id;
        Mwrl::ComPtr<IMMDevice> device;
        if (SUCCEEDED(GetAudioDeviceAssociation(audioDeviceEnumerator.Get(), userLocalId, XUserDefaultAudioEndpointKind::CommunicationCapture, &device)))
        {
            RETURN_IF_FAILED(device->GetId(&id));
        }
        appLog.AddLog("Preferred capture communication device id: %S\n", id.get());
    }

    return S_OK;
}
```

## Requirements

**Header:** XUser.h

**Library:** xgameruntime.lib

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

## Conceptual documentation

* [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## See also

[XUser](/reference/system/xuser/xuser_members)

[XUserDefaultAudioEndpointUtf16ChangedCallback](/reference/system/xuser/functions/xuserdefaultaudioendpointutf16changedcallback)

[XUserRegisterForDefaultAudioEndpointUtf16Changed](/reference/system/xuser/functions/xuserregisterfordefaultaudioendpointutf16changed)

[XUserUnregisterForDefaultAudioEndpointUtf16Changed](/reference/system/xuser/functions/xuserunregisterfordefaultaudioendpointutf16changed)


## Related topics

- [XUserDefaultAudioEndpointKind](/reference/system/xuser/enums/xuserdefaultaudioendpointkind.md)
- [XUserLocalId](/reference/system/xuser/structs/xuserlocalid.md)
- [Users and input devices](/build/core-features/common/user/users-input-devices.md)
- [XUser](/reference/system/xuser/xuser_members.md)
- [Unity C# API wrappers for the GDK](/build/gdk-and-engines/unity/unity-api-wrappers.md)
