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

# XUserGetLocalId

> XUserGetLocalId

# XUserGetLocalId

ユーザーの一意なゲーム セッション ID を取得します。

## 構文

```cpp theme={null}
HRESULT XUserGetLocalId(  
         XUserHandle user,  
         XUserLocalId* userLocalId  
)  
```

### パラメーター

*user*   \_In\_\
Type: XUserHandle

ローカル ID を取得する対象のユーザーへのハンドルです。

*userLocalId*   \_Out\_\
Type: [XUserLocalId\*](/reference/system/xuser/structs/xuserlocalid)

ユーザーの一意なゲーム セッション ID が格納されます。

### 戻り値

Type: HRESULT

HRESULT の成功またはエラー コード。\
エラー コードの一覧については、[エラー コード](/reference/errorcodes) を参照してください。

## 解説

特定のユーザーのユーザー ID を取得するには、[XUserGetId](/reference/system/xuser/functions/xusergetid) を呼び出します。

特定のユーザーの状態を取得するには、[XUserGetState](/reference/system/xuser/functions/xusergetstate) を呼び出します。

特定のユーザーの年齢グループを取得するには、[XUserGetAgeGroup](/reference/system/xuser/functions/xusergetagegroup) を呼び出します。

**XUserLocalId** は、ゲーム セッション内でユーザーを一意に識別します。**XUserHandle** を複製した場合、両方のハンドルは同じ **XUserLocalId** を保持します。ゲーム セッションが終了すると、同じユーザーであっても次のセッションでは異なる **XUserLocalId** が付与される可能性があります。これらの ID を、ゲーム セッションをまたいでユーザーを追跡する目的で使用しないでください。

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

```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、Steam Deck、XBOX One ファミリ本体および XBOX Series 本体

## 関連項目

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

[XUserGetId](/reference/system/xuser/functions/xusergetid)

[XUserGetState](/reference/system/xuser/functions/xusergetstate)

[XUserGetAgeGroup](/reference/system/xuser/functions/xusergetagegroup)


## Related topics

- [XUserLocalId](/ja-jp/reference/system/xuser/structs/xuserlocalid.md)
- [ユーザー ID と XUser](/ja-jp/build/core-features/common/user/player-identity-xuser.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)
