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

## Syntax

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

### Parameters

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

指向游戏 TitleID 的指针。

### Return value

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

如果成功，则返回 **S\_OK**；否则返回错误代码。有关错误代码的列表，请参阅[错误代码](/reference/errorcodes)。如果游戏开发者未在 MicrosoftGame.config 文件中配置 TitleID，则返回值设置为 **HRESULT\_FROM\_WIN32(ERROR\_NOT\_FOUND)**。

## Remarks

<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();  
}   
```

## Requirements

**头文件：** XGame.h

**库：** xgameruntime.lib

**受支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## Conceptual documentation

* [时间敏感型线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## See also

[MicrosoftGame.config](/build/core-features/common/game-config/MicrosoftGameConfig-toc)\
[XGame](/reference/system/xgame/xgame_members)\
[为 XBOX Live 开发设置沙盒](/services/xbox-services/fundamentals/sandboxes/live-setting-up-sandboxes)


## Related topics

- [XGame](/zh-CN/reference/system/xgame/xgame_members.md)
- [MicrosoftGame.config 元素 - TitleId](/zh-CN/reference/system/microsoftgameconfig/elements/microsoftgameconfig-element-titleid.md)
- [XBOX Live Title 关联](/zh-CN/services/playfab/identity/player-identity/platform-specific-authentication/xbox-live-add-on.md)
- [XblAchievementsGetAchievementsForTitleIdAsync](/zh-CN/reference/live/xsapi-c/achievements_c/functions/xblachievementsgetachievementsfortitleidasync.md)
- [XblAchievementsGetAchievementsForTitleIdResult](/zh-CN/reference/live/xsapi-c/achievements_c/functions/xblachievementsgetachievementsfortitleidresult.md)
