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

# 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**；否则返回错误代码。有关错误代码的列表，请参阅[错误代码](https://docs.xbox.com/zh-CN/reference/errorcodes.md)。如果游戏开发者未在 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)。

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](https://docs.xbox.com/zh-CN/build/core-features/common/game-config/MicrosoftGameConfig-toc.md)\
[XGame](https://docs.xbox.com/zh-CN/reference/system/xgame/xgame_members.md)\
[为 XBOX Live 开发设置沙盒](https://docs.xbox.com/zh-CN/services/xbox-services/fundamentals/sandboxes/live-setting-up-sandboxes.md)


## Related topics

- [XGame（API 内容）](https://docs.xbox.com/zh-CN/reference/system/xgame/xgame_members.md)
- [Login With Xbox Id](https://docs.xbox.com/api-reference/authentication/login-with-xbox-id.md)
- [TitleId 元素 (MicrosoftGame.config)](https://docs.xbox.com/zh-CN/reference/system/microsoftgameconfig/elements/microsoftgameconfig-element-titleid.md)
- [GET /titles/{titleId}/users/{xuid}/activities API](https://docs.xbox.com/zh-CN/reference/live/rest/uri/multiplayeractivity/swagger-uris/uri-GetActivity.md)
- [Get Title Players From Xbox Live IDs](https://docs.xbox.com/api-reference/account-management/get-title-players-from-xbox-live-ids.md)
