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

# XPackageMountWithUiAsync

> XPackageMountWithUiAsync

# XPackageMountWithUiAsync

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

## 语法

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

### 参数

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

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

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

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

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

## 备注

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

此 API 会自动调用 [XStoreAcquireLicenseForPackageAsync](/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync) / [Result](/reference/system/xstore/functions/xstoreacquirelicenseforpackageresult) 和 [XStoreIsLicenseValid](/reference/system/xstore/functions/xstoreislicensevalid)。
如果 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)](/build/core-features/common/packaging/supporting-games-as-a-service)

## 另请参阅

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


## Related topics

- [[DEPRECATED] XPackageMount](/zh-CN/reference/system/xpackage/functions/xpackagemount.md)
- [支持游戏即服务(GaaS)](/zh-CN/build/core-features/common/packaging/supporting-games-as-a-service.md)
- [XPackage](/zh-CN/reference/system/xpackage/xpackage_members.md)
- [XStoreAcquireLicenseForPackageAsync](/zh-CN/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync.md)
- [面向 GDK 的 Unity C# API 包装器](/zh-CN/build/gdk-and-engines/unity/unity-api-wrappers.md)
