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

Specifies a game session ID for a user.

## Syntax

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

### Members

*value*\
Type: uint64\_t

The game session ID for a user.

## Remarks

The XUserLocalId uniquely identifies a user within a gaming session. If we duplicate **XUserHandle**, both handles maintain the same XUserLocalId. Once a gaming session ends, the same user can have a different XUserLocalIds in the next session. You cannot use these IDs to track users across gaming sessions. The IDs are valid per gaming session.

A "null" XUserLocalId will be equal to the value of **XUserNullUserLocalId**.

The following callback functions and function take an XUserLocalId structure or a pointer to one as an argument:

* [XUserChangeEventCallback](/reference/system/xuser/functions/xuserchangeeventcallback): A callback function for a user change event.
* [XUserDefaultAudioEndpointUtf16ChangedCallback](/reference/system/xuser/functions/xuserdefaultaudioendpointutf16changedcallback): A callback that invokes when the default audio endpoint for a user changes.
* [XUserFindUserByLocalId](/reference/system/xuser/functions/xuserfinduserbylocalid): A function that uses a specific local ID to retrieve a handle to a user.
* [XUserGetDefaultAudioEndpointUtf16](/reference/system/xuser/functions/xusergetdefaultaudioendpointutf16): A function that retrieves the default audio endpoint for a specific user.
* [XUserGetLocalId](/reference/system/xuser/functions/xusergetlocalid): A function that retrieves the unique game session ID for a user.

The following example demonstrates how to use the XUserLocalId structure 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

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

## See also

[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](/reference/system/xuser/functions/xusergetlocalid.md)
- [XUserFindUserByLocalId](/reference/system/xuser/functions/xuserfinduserbylocalid.md)
- [APP_LOCAL_DEVICE_ID](/reference/system/xuser/structs/app_local_device_id.md)
- [XUserDeviceAssociationChange](/reference/system/xuser/structs/xuserdeviceassociationchange.md)
- [XUserChangeEventCallback](/reference/system/xuser/functions/xuserchangeeventcallback.md)
