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

# XGameGetXboxTitleId

> XGameGetXboxTitleId

# XGameGetXboxTitleId

傳回遊戲的 TitleID。

## 語法

```cpp theme={null}
HRESULT XGameGetXboxTitleId(  
         uint32_t* titleId  
)  
```

### 參數

*titleId*   \_Out\_\
類型：uint32\_t\*

遊戲 TitleID 的指標。

### 傳回值

類型：[HRESULT](https://learn.microsoft.com/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a)

如果成功，則傳回 **S\_OK**；否則傳回錯誤碼。如需錯誤碼清單，請參閱[錯誤碼](/zh-TW/reference/errorcodes)。如果遊戲開發人員未在 MicrosoftGame.config 檔案中設定 TitleID，則傳回值會設定為 **HRESULT\_FROM\_WIN32(ERROR\_NOT\_FOUND)**。

## 備註

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

TitleID 會向 XBOX Live 服務唯一識別您的遊戲。XBOX Live 服務會全面使用它，讓您的使用者能存取遊戲的 Live 內容 (例如使用者統計資料和成就)，並啟用 Live 多人遊戲功能。TitleID 儲存在遊戲的 MicrosoftGame.config 資訊清單檔案中。

下列範例會產生用於呼叫遊戲所使用之後端 REST 服務的 URL。系統會呼叫 **XGameGetXBoxTitleId** 函式，將 TitleID 納入 URL 中。

```cpp theme={null}
std::string GetBackendServiceUrl()  
{  
    uint32_t titleId;  
  
    RetailAssert(SUCCEEDED(XGameGetXboxTitleId(&titleId)));  
  
    std::stringstream url;  
    url << "https://example.com/some/api/call";  
  
    url << std::hex << std::uppercase << std::setfill('0');  
    url << "/titleId/" << std::setw(8) << titleId;  
  
    return url.str();  
}   
```

## 需求

**標頭：** XGame.h

**程式庫：** xgameruntime.lib

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 概念文件

* [時間敏感的執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 另請參閱

[MicrosoftGame.config](/zh-TW/build/core-features/common/game-config/MicrosoftGameConfig-toc)\
[XGame](/zh-TW/reference/system/xgame/xgame_members)\
[設定 XBOX Live 開發的沙箱](/zh-TW/services/xbox-services/fundamentals/sandboxes/live-setting-up-sandboxes)


## Related topics

- [XGame](/zh-TW/reference/system/xgame/xgame_members.md)
- [Login With Xbox Id](/api-reference/authentication/login-with-xbox-id.md)
- [Get Title Players From Xbox Live IDs](/api-reference/account-management/get-title-players-from-xbox-live-ids.md)
- [使用 Xbox ID 登入](/zh-TW/services/playfab/api-references/rest/server/authentication/login-with-xbox-id.md)
- [Get Account Info](/api-reference/account-management/get-account-info.md)
