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

# XPackageMountWithUiAsync

> XPackageMountWithUiAsync

# XPackageMountWithUiAsync

异步装载指定内容的安装，并返回其装载句柄。
如果内容根据所有已登录用户的家长设置存在年龄限制，则会显示用户家长同意 UI。

## 语法

```cpp theme={null}
HRESULT XPackageMountWithUiAsync(
  const char * packageIdentifier,
  XAsyncBlock * async
) noexcept;
```

### 参数

*packageIdentifier*  \_In\_z\_\
类型：const char \*

用于在磁盘上唯一标识已安装包的字符串。
传入从 [XPackageEnumerationCallback](https://docs.xbox.com/zh-CN/reference/system/xpackage/functions/xpackageenumerationcallback.md) 返回的 [XPackageDetails](https://docs.xbox.com/zh-CN/reference/system/xpackage/structs/xpackagedetails.md) 结构中的 packageIdentifier 字段。
有关包标识符的详细信息，请参阅[管理和授权可下载内容 (DLC)](https://docs.xbox.com/zh-CN/publishing/xstore-commerce/xstore-dlc.md)。

*async*  \_Inout\_\
类型：XAsyncBlock \*

用于监视异步调用状态的 **XAsyncBlock**。

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

## 备注

如果此 API 装载的内容对所有已登录用户来说都不符合年龄要求，则该 API 会向用户显示家长同意提示。
如果成年用户在提示中同意家长授权，则该 API 会尝试装载包。
如果成年用户在提示中拒绝家长授权，则该 API 将无法装载包。

此 API 会自动调用 [XStoreAcquireLicenseForPackageAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync.md) / [Result](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreacquirelicenseforpackageresult.md) 和 [XStoreIsLicenseValid](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreislicensevalid.md)。
如果 API 无法获取 DLC 的有效许可证，则装载将失败。

在此代码示例中，如果内容有年龄限制，游戏将以黑白方式呈现 DLC。
当用户选择要使用的 DLC 时，游戏中的外部代码会调用 `MountDlc`。

```cpp theme={null}
extern void RenderDlc(const char* packageId, const char* displayName, bool monochrome); 

void ShowDlc() 
{ 
// Enumerate all DLC for the game and render it to the user 
XPackageEnumeratePackages(XPackageKind::Content, XPackageEnumerationScope::ThisAndRelated, nullptr,
 [](void*, const XPackageDetails* details) 
  {     
        RenderDlc(details->packageIdentifier,
                  details->displayName, 
                  details->ageRestricted);
  }); 
} 

 HRESULT MountDlc(const char* packageId, XPackageMountHandle* handle)
 {  
    XAsync async{};  
    RETURN_IF_FAILED(XPackageMountWithUiAsync(packageId, &async));
    RETURN_IF_FAILED(XAsyncGetStatus(&async, true));
    RETURN_IF_FAILED(XPackageMountWithUiResult(&async, handle));  
    return S_OK; 
} 
```

## 要求

**头文件：** XPackage.h

**库：** xgameruntime.lib

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

## 概念文档

* [支持游戏即服务 (GaaS)](https://docs.xbox.com/zh-CN/build/core-features/common/packaging/supporting-games-as-a-service.md)

## 另请参阅

[XPackageMountWithUiResult](https://docs.xbox.com/zh-CN/reference/system/xpackage/functions/xpackagemountwithuiresult.md)
[XPackage](https://docs.xbox.com/zh-CN/reference/system/xpackage/xpackage_members.md)\
[XPackageEnumeratePackages](https://docs.xbox.com/zh-CN/reference/system/xpackage/functions/xpackageenumeratepackages.md)\
[XPackageEnumerationCallback](https://docs.xbox.com/zh-CN/reference/system/xpackage/functions/xpackageenumerationcallback.md)\
[XPackageDetails](https://docs.xbox.com/zh-CN/reference/system/xpackage/structs/xpackagedetails.md)\
[XPackageGetMountPath](https://docs.xbox.com/zh-CN/reference/system/xpackage/functions/xpackagegetmountpath.md)\
[XPackageGetMountPathSize](https://docs.xbox.com/zh-CN/reference/system/xpackage/functions/xpackagegetmountpathsize.md)\
[如何为 PC 和 XBOX One 创建和使用可下载内容包 (DLC)](https://docs.xbox.com/zh-CN/build/core-features/common/packaging/packaging-downloadable-content-dlc.md)


## Related topics

- [XPackageMount](https://docs.xbox.com/zh-CN/reference/system/xpackage/functions/xpackagemount.md)
- [支持游戏即服务 (GaaS)](https://docs.xbox.com/zh-CN/build/core-features/common/packaging/supporting-games-as-a-service.md)
- [XPackage（API 内容）](https://docs.xbox.com/zh-CN/reference/system/xpackage/xpackage_members.md)
- [XStoreAcquireLicenseForPackageAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync.md)
- [发布者内容包](https://docs.xbox.com/zh-CN/build/core-features/common/packaging/packaging-publisher-content.md)
