> ## 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

特定のユーザーの既定のオーディオ エンドポイントを取得します。

## 構文

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

### パラメーター

*user*   \
Type: [XUserLocalId](/reference/system/xuser/structs/xuserlocalid)\
既定のオーディオ エンドポイントを取得する対象のユーザーのローカル ID です。

*defaultAudioEndpointKind*   \
Type: [XUserDefaultAudioEndpointKind](/reference/system/xuser/enums/xuserdefaultaudioendpointkind)\
ユーザーの既定のオーディオ エンドポイントがオーディオをレンダリングするかキャプチャするかを指定する列挙値です。

*endpointIdUtf16Count*   \
Type: size\_t\
*endpointIdUtf16* パラメーターが指すバッファーの wchar\_t 数です。**XUserAudioEndpointMaxUtf16Count** を渡します。

*endpointIdUtf16*   \_Out\_writes\_to\_(endpointIdUtf16Count,*endpointIdUtf16Used)\
Type: wchar\_t*\
ユーザーの既定のオーディオ エンドポイントの ID が格納されます。

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

*endpointIdUtf16* パラメーターが返す ID の実際の wchar\_t 数が格納されます。

### 戻り値

Type: HRESULT

成功した場合は S\_OK を返します。それ以外の場合はエラー コードを返します。
エラー コードの一覧については、[エラー コード](/reference/errorcodes) を参照してください。

## 解説

<Note>この関数は、時間依存スレッドから呼び出しても安全ではありません。詳細については、[時間依存スレッド](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads) を参照してください。</Note>

XUserGetDefaultAudioEndpointUtf16 関数は、引数として [XUserDefaultAudioEndpointKind](/reference/system/xuser/enums/xuserdefaultaudioendpointkind) 列挙値を受け取ります。

[XUserDefaultAudioEndpointUtf16ChangedCallback](/reference/system/xuser/functions/xuserdefaultaudioendpointutf16changedcallback) コールバック関数は、特定ユーザーの既定のオーディオ エンドポイントが変更されたときに呼び出されます。

既定のオーディオ エンドポイントが変更されたときにコールバックを受け取るように登録するには、[XUserRegisterForDefaultAudioEndpointUtf16Changed](/reference/system/xuser/functions/xuserregisterfordefaultaudioendpointutf16changed) を呼び出します。

既定のオーディオ エンドポイントが変更されたときのコールバック登録を解除するには、[XUserUnregisterForDefaultAudioEndpointUtf16Changed](/reference/system/xuser/functions/xuserunregisterfordefaultaudioendpointutf16changed) を呼び出します。

以下の例は、ユーザーの既定のオーディオ エンドポイントを取得する方法を示しています。

```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;
}
```

## 要件

**ヘッダー:** XUser.h

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One ファミリ本体および XBOX Series 本体

## 概念ドキュメント

* [時間依存スレッド](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 関連項目

[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](/ja-jp/reference/system/xuser/enums/xuserdefaultaudioendpointkind.md)
- [XUserLocalId](/ja-jp/reference/system/xuser/structs/xuserlocalid.md)
- [ユーザーと入力デバイス](/ja-jp/build/core-features/common/user/users-input-devices.md)
- [XUser](/ja-jp/reference/system/xuser/xuser_members.md)
- [GDK 向け Unity C# API ラッパー](/ja-jp/build/gdk-and-engines/unity/unity-api-wrappers.md)
