> ## 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 使用者識別碼 (XUID) 擷取 XUserHandle。

## 語法

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

### 參數

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

要擷取其 XUID 的本機使用者。

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

包含本機使用者的 XUID。

### 傳回值

類型：HRESULT

HRESULT 成功或錯誤碼。\
如需錯誤碼清單，請參閱[錯誤碼](/zh-TW/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](/zh-TW/reference/system/xuser/functions/xuserclosehandle) 來關閉該控制代碼。

若要擷取本機使用者的 XBox 使用者識別碼 (XUID)，請呼叫 XUserFindUserById。

若要擷取特定本機使用者識別碼的使用者控制代碼，請呼叫 [XUserFindUserByLocalId](/zh-TW/reference/system/xuser/functions/xuserfinduserbylocalid)。

若要擷取特定裝置識別碼的使用者識別碼，請呼叫 [XUserFindForDevice](/zh-TW/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](/zh-TW/services/xbox-services/multiplayer/chat/game-chat2/using-game-chat-2)

## 另請參閱

[XUser](/zh-TW/reference/system/xuser/xuser_members)

[XUserFindUserByLocalId](/zh-TW/reference/system/xuser/functions/xuserfinduserbylocalid)

[XUserFindForDevice](/zh-TW/reference/system/xuser/functions/xuserfindfordevice)


## Related topics

- [XUserFindUserById](/reference/system/xuser/functions/xuserfinduserbyid.md)
- [XUserFindUserByLocalId](/reference/system/xuser/functions/xuserfinduserbylocalid.md)
