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

# XUserLocalId

> XUserLocalId

# XUserLocalId

ユーザーのゲーム セッション ID を指定します。

## 構文

```cpp theme={null}
typedef struct XUserLocalId {  
    uint64_t value;  
} XUserLocalId  
```

### メンバー

*value*\
Type: uint64\_t

ユーザーのゲーム セッション ID です。

## 解説

XUserLocalId は、ゲーム セッション内でユーザーを一意に識別します。**XUserHandle** を複製した場合、両方のハンドルは同じ XUserLocalId を保持します。ゲーム セッションが終了すると、同じユーザーが次のセッションで異なる XUserLocalId を持つ可能性があります。これらの ID を使ってゲーム セッションをまたがるユーザーを追跡することはできません。この ID はゲーム セッションごとに有効です。

「null」の XUserLocalId は、**XUserNullUserLocalId** の値と等しくなります。

以下のコールバック関数および関数は、XUserLocalId 構造体、またはそのポインターを引数として使用します。

* [XUserChangeEventCallback](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xuserchangeeventcallback.md): ユーザー変更イベント用のコールバック関数。
* [XUserDefaultAudioEndpointUtf16ChangedCallback](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xuserdefaultaudioendpointutf16changedcallback.md): ユーザーの既定のオーディオ エンドポイントが変更されたときに呼び出されるコールバック。
* [XUserFindUserByLocalId](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xuserfinduserbylocalid.md): 特定のローカル ID を使用してユーザーのハンドルを取得する関数。
* [XUserGetDefaultAudioEndpointUtf16](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xusergetdefaultaudioendpointutf16.md): 特定のユーザーの既定のオーディオ エンドポイントを取得する関数。
* [XUserGetLocalId](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xusergetlocalid.md): ユーザーの一意なゲーム セッション 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

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

## 関連項目

[XUser](https://docs.xbox.com/ja-jp/reference/system/xuser/xuser_members.md)

[XUserChangeEventCallback](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xuserchangeeventcallback.md)

[XUserDefaultAudioEndpointUtf16ChangedCallback](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xuserdefaultaudioendpointutf16changedcallback.md)

[XUserFindUserByLocalId](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xuserfinduserbylocalid.md)

[XUserGetDefaultAudioEndpointUtf16](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xusergetdefaultaudioendpointutf16.md)

[XUserGetLocalId](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xusergetlocalid.md)


## Related topics

- [XUserGetLocalId](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xusergetlocalid.md)
- [APP_LOCAL_DEVICE_ID](https://docs.xbox.com/ja-jp/reference/system/xuser/structs/app_local_device_id.md)
- [XUserFindUserByLocalId](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xuserfinduserbylocalid.md)
- [XUserDeviceAssociationChange](https://docs.xbox.com/ja-jp/reference/system/xuser/structs/xuserdeviceassociationchange.md)
- [XUserChangeEventCallback](https://docs.xbox.com/ja-jp/reference/system/xuser/functions/xuserchangeeventcallback.md)
