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

# XUserFindUserById

> XUserFindUserById

# XUserFindUserById

基于本地用户的 XBOX 用户 ID (XUID) 检索 XUserHandle。

## 语法

```cpp theme={null}
HRESULT XUserFindUserById(  
         uint64_t userId,  
         XUserHandle* handle  
)  
```

### 参数

*userId*   \_In\_\
类型：uint64\_t

要检索 XUID 的本地用户。

*handle*   \_Out\_\
类型：XUserHandle\*

包含本地用户的 XUID。

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。\
有关错误代码列表，请参阅[错误代码](/reference/errorcodes)。

## 注解

<Note>在时间敏感线程上调用此函数并不安全。有关详细信息，请参阅[时间敏感线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。</Note>

对于从 **XUser** API（包括 **XUserFindUserById**）检索到的每个 **XUserHandle** 句柄，必须通过调用 [XUserCloseHandle](/reference/system/xuser/functions/xuserclosehandle) 关闭该句柄。

若要检索本地用户的 XBOX 用户 ID (XUID)，请调用 XUserFindUserById。

若要检索特定本地用户 ID 对应的用户句柄，请调用 [XUserFindUserByLocalId](/reference/system/xuser/functions/xuserfinduserbylocalid)。

若要检索特定设备 ID 对应的用户 ID，请调用 [XUserFindForDevice](/reference/system/xuser/functions/xuserfindfordevice)。

## 要求

**头文件：** XUser.h

**库：** xgameruntime.lib

**支持的平台：** Windows、Steam Deck、XBOX One 系列主机和 XBOX Series 主机

## 概念文档

* [时间敏感线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)
* [使用 Game Chat 2 C++ API](/services/xbox-services/multiplayer/chat/game-chat2/using-game-chat-2)

## 另请参阅

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

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

[XUserFindForDevice](/reference/system/xuser/functions/xuserfindfordevice)


## Related topics

- [XUserFindUserByLocalId](/zh-CN/reference/system/xuser/functions/xuserfinduserbylocalid.md)
- [XUserGetId](/zh-CN/reference/system/xuser/functions/xusergetid.md)
- [使用 Game Chat 2 C++ API](/zh-CN/services/xbox-services/multiplayer/chat/game-chat2/using-game-chat-2.md)
- [XUser](/zh-CN/reference/system/xuser/xuser_members.md)
- [面向 GDK 的 Unity C# API 包装器](/zh-CN/build/gdk-and-engines/unity/unity-api-wrappers.md)
