> ## Documentation Index
> Fetch the complete documentation index at: https://docs.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\*](https://docs.xbox.com/zh-CN/reference/system/xuser/structs/app_local_device_id.md)

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

包含本地用户的 XUID。

### 返回值

类型：HRESULT

如果成功，则返回 S\_OK；否则返回错误代码。
有关错误代码列表，请参阅[错误代码](https://docs.xbox.com/zh-CN/reference/errorcodes.md)。

## 注解

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

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

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

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

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

## 要求

**头文件：** 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](https://docs.xbox.com/zh-CN/reference/system/xuser/xuser_members.md)

[XUserRegisterForDeviceAssociationChanged](https://docs.xbox.com/zh-CN/reference/system/xuser/functions/xuserregisterfordeviceassociationchanged.md)

[XUserDeviceAssociationChangedCallback](https://docs.xbox.com/zh-CN/reference/system/xuser/functions/xuserdeviceassociationchangedcallback.md)


## Related topics

- [XUserFindUserById](https://docs.xbox.com/zh-CN/reference/system/xuser/functions/xuserfinduserbyid.md)
- [XUserFindUserByLocalId](https://docs.xbox.com/zh-CN/reference/system/xuser/functions/xuserfinduserbylocalid.md)
- [APP_LOCAL_DEVICE_ID](https://docs.xbox.com/zh-CN/reference/system/xuser/structs/app_local_device_id.md)
- [用户与输入设备](https://docs.xbox.com/zh-CN/build/core-features/common/user/users-input-devices.md)
- [XUser（API 内容）](https://docs.xbox.com/zh-CN/reference/system/xuser/xuser_members.md)
