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

# XUserFindUserByLocalId

> XUserFindUserByLocalId

# XUserFindUserByLocalId

检索特定本地用户 ID 对应的用户句柄。

## 语法

```cpp theme={null}
HRESULT XUserFindUserByLocalId(  
         XUserLocalId userLocalId,  
         XUserHandle* handle  
)  
```

### 参数

*userLocalId*   \_In\_\
类型：[XUserLocalId](/reference/system/xuser/structs/xuserlocalid)

要获取用户的本地 ID。

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

包含与特定本地用户 ID 关联的用户句柄。

### 返回值

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

类型：HRESULT

HRESULT 成功或错误代码。

| 返回代码                                    | 说明      |
| --------------------------------------- | ------- |
| S\_OK                                   | 操作成功。   |
| HRESULT\_FROM\_WIN32(ERROR\_NOT\_FOUND) | 未找到该用户。 |

## 注解

对于从 **XUser** API（包括 **XUserFindUserByLocalId**）检索到的每个 **XUserHandle** 句柄，必须通过调用 [XUserCloseHandle](/reference/system/xuser/functions/xuserclosehandle) 关闭该句柄。调用 Get / Find 函数后，句柄的引用计数会增加。

若要检索特定本地用户 ID 对应的用户句柄，请调用 XUserFindUserByLocalId。

若要检索本地用户的 XBOX 用户 ID (XUID)，请调用 [XUserFindUserById](/reference/system/xuser/functions/xuserfinduserbyid)。

若要检索特定设备 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)

## 另请参阅

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

[XUserFindUserById](/reference/system/xuser/functions/xuserfinduserbyid)

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


## Related topics

- [XUserFindUserById](/zh-CN/reference/system/xuser/functions/xuserfinduserbyid.md)
- [XUserLocalId](/zh-CN/reference/system/xuser/structs/xuserlocalid.md)
- [XUserGetId](/zh-CN/reference/system/xuser/functions/xusergetid.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)
