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

擷取特定裝置識別碼的使用者識別碼。

## 語法

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

### 參數

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

裝置的識別碼。\
*handle*   \_Out\_\
類型：XUserHandle\*

包含本機使用者的 XUID。

### 傳回值

類型：HRESULT

如果成功，則傳回 S\_OK；否則傳回錯誤碼。
如需錯誤碼清單，請參閱[錯誤碼](/zh-TW/reference/errorcodes)。

## 備註

<Note>在時間敏感執行緒上呼叫此函式並不安全。如需詳細資訊，請參閱[時間敏感執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。</Note>

使用者與裝置之間的關聯可能因許多原因而變更：

* 使用者從主機登出。
* 有人使用輸入裝置在帳戶選擇器中選取其他使用者。

若要在使用者與裝置的關聯變更時收到通知，請呼叫 [XUserRegisterForDeviceAssociationChanged](/zh-TW/reference/system/xuser/functions/xuserregisterfordeviceassociationchanged) 以取得 [XUserDeviceAssociationChangedCallback](/zh-TW/reference/system/xuser/functions/xuserdeviceassociationchangedcallback)。

<Note>*XUserFindForDevice* 無法傳回尚未透過呼叫 [XUserAddAsync](/zh-TW/reference/system/xuser/functions/xuseraddasync) 登入之使用者的使用者控制代碼。如需詳細資訊，請參閱[使用者與輸入裝置](/zh-TW/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](/zh-TW/reference/system/xuser/xuser_members)

[XUserRegisterForDeviceAssociationChanged](/zh-TW/reference/system/xuser/functions/xuserregisterfordeviceassociationchanged)

[XUserDeviceAssociationChangedCallback](/zh-TW/reference/system/xuser/functions/xuserdeviceassociationchangedcallback)


## Related topics

- [XUserFindForDevice](/reference/system/xuser/functions/xuserfindfordevice.md)
- [XUserFindUserById](/reference/system/xuser/functions/xuserfinduserbyid.md)
