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

# XUserFindForDevice

> XUserFindForDevice

# XUserFindForDevice

检索特定设备 ID 对应的用户 ID。

## 语法

```cpp theme={null}
HRESULT XUserFindForDevice(  
         const APP_LOCAL_DEVICE_ID* deviceId,  
         XUserHandle* handle  
)  
```

### 参数

*deviceId*   \_In\_\
类型：[APP\_LOCAL\_DEVICE\_ID\*](/reference/system/xuser/structs/app_local_device_id)

设备的 ID。\
*handle*   \_Out\_\
类型：XUserHandle\*

包含本地用户的 XUID。

### 返回值

类型：HRESULT

如果成功，则返回 S\_OK；否则返回错误代码。
有关错误代码列表，请参阅[错误代码](/reference/errorcodes)。

## 注解

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

用户与设备之间的关联可能因多种原因而更改：

* 用户从主机注销。
* 有人在帐户选择器中使用输入设备选择了不同的用户。

若要在用户-设备关联更改时接收通知，请调用 [XUserRegisterForDeviceAssociationChanged](/reference/system/xuser/functions/xuserregisterfordeviceassociationchanged) 以获取 [XUserDeviceAssociationChangedCallback](/reference/system/xuser/functions/xuserdeviceassociationchangedcallback)。

<Note>*XUserFindForDevice* 无法为尚未通过调用 [XUserAddAsync](/reference/system/xuser/functions/xuseraddasync) 登录的用户返回用户句柄。有关详细信息，请参阅[用户和输入设备](/build/core-features/common/user/users-input-devices)。</Note>

## 要求

**头文件：** XUser.h

**库：** xgameruntime.lib

**支持的平台：** Windows、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)

[XUserRegisterForDeviceAssociationChanged](/reference/system/xuser/functions/xuserregisterfordeviceassociationchanged)

[XUserDeviceAssociationChangedCallback](/reference/system/xuser/functions/xuserdeviceassociationchangedcallback)


## Related topics

- [XUserFindUserById](/zh-CN/reference/system/xuser/functions/xuserfinduserbyid.md)
- [XUserFindUserByLocalId](/zh-CN/reference/system/xuser/functions/xuserfinduserbylocalid.md)
- [APP_LOCAL_DEVICE_ID](/zh-CN/reference/system/xuser/structs/app_local_device_id.md)
- [XUser](/zh-CN/reference/system/xuser/xuser_members.md)
- [用户与输入设备](/zh-CN/build/core-features/common/user/users-input-devices.md)
