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

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

[XUserChangeEventCallback](/reference/system/xuser/functions/xuserchangeeventcallback)

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

[XUserFindUserByLocalId](/reference/system/xuser/functions/xuserfinduserbylocalid)

[XUserGetDefaultAudioEndpointUtf16](/reference/system/xuser/functions/xusergetdefaultaudioendpointutf16)

[XUserGetLocalId](/reference/system/xuser/functions/xusergetlocalid)


## Related topics

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