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

# XStoreShowPurchaseUIAsync

> XStoreShowPurchaseUIAsync

# XStoreShowPurchaseUIAsync

启动指定产品的购买 UI 覆盖。

## 语法

```cpp theme={null}
HRESULT XStoreShowPurchaseUIAsync(  
         const XStoreContextHandle storeContextHandle,  
         const char* storeId,  
         const char* name,  
         const char* extendedJsonData,  
         XAsyncBlock* async  
)  
```

### 参数

*storeContextHandle*   \_In\_\
类型：XStoreContextHandle

[XStoreCreateContext](/reference/system/xstore/functions/xstorecreatecontext) 为用户返回的商店上下文句柄。

*storeId*   \_In\_z\_\
类型：char\*

要购买的产品的 ID。

*name*   \_In\_opt\_z\_\
类型：char\*

要购买的产品名称。

*extendedJsonData*   \_In\_opt\_z\_\
类型：char\*

传递给购买流程的 json 数据块。允许插入自定义营销活动 ID，以便你可以跟踪购买是如何启动的。

*async*   \_Inout\_\
类型：[XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

定义正在完成的异步工作的 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。[XAsyncBlock](/reference/system/xasync/structs/xasyncblock) 可用于轮询调用的状态并检索调用结果。有关详细信息，请参阅 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

## 备注

> !\[NOTE] 此操作不会在预期购买后触发项目的下载或安装。如果你希望下载并安装此内容，建议在成功购买后调用 [XStoreDownloadAndInstallPackagesAsync](/reference/system/xstore/functions/xstoredownloadandinstallpackagesasync)。不会向用户提供其他提示。

> !\[NOTE] 在 PC 上，购买成功后显示的购买确认对话框将在顶部有一个关闭按钮 \[X]。选择该按钮而不是"确定"将导致 `XStoreShowPurchaseUIResult` 返回 E\_ABORT，这可能不是所需的结果。当以此方式关闭任何对话框时，这是 Windows 的标准行为。

要检索此函数调用的结果，请在调用此函数之后调用 [XStoreShowPurchaseUIResult](/reference/system/xstore/functions/xstoreshowpurchaseuiresult)。仅当用户选择购买某项时，才应调用此函数，这将使系统显示一个模态购买对话框，用于在进程外处理付款信息和用户确认。

以下代码片段展示了为特定商店产品请求购买的示例。

```cpp theme={null}
void CALLBACK ShowPurchaseUICallback(XAsyncBlock* asyncBlock)
{
    HRESULT hr = XStoreShowPurchaseUIResult(asyncBlock);

    if (FAILED(hr))
    {
        printf("Failed the purchase: 0x%x\r\n", hr);
        return;
    }
}

void ShowPurchaseUI(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char* storeId)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->callback = ShowPurchaseUICallback;

    HRESULT hr = XStoreShowPurchaseUIAsync(
        storeContextHandle,
        storeId,
        nullptr,    // Can be used to override the title bar text
        nullptr,    // Can be used to provide extra details to purchase
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to purchase: 0x%x\r\n", hr);
        return;
    }
}
```

## 要求

**头文件：** XStore.h（包含在 XGameRuntime.h 中）

**库：** xgameruntime.lib

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

## 概念文档

* [在游戏中实现游戏内购买](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/pc-dev/tutorials/pc-e2e-guide/e2e-services/e2e-in-game-purchases)
* [基本商店操作](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-basic-store-operations)
* [管理和许可可下载内容 (DLC)](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-manage-and-license-optional-packages)
* [XStore 开发故障排除](/publishing/xstore-commerce/xstore-troubleshooting)

## 另请参阅

[XStore](/reference/system/xstore/xstore_members)\
[XStoreShowPurchaseUIResult](/reference/system/xstore/functions/xstoreshowpurchaseuiresult)


## Related topics

- [XStoreShowPurchaseUIResult](/zh-CN/reference/system/xstore/functions/xstoreshowpurchaseuiresult.md)
- [排查 XStore 开发问题](/zh-CN/publishing/xstore-commerce/xstore-troubleshooting.md)
- [商店基本操作](/zh-CN/publishing/xstore-commerce/xstore-basic-operations.md)
- [可选服务](/zh-CN/build/gdk-and-engines/optional-services.md)
- [XStore](/zh-CN/reference/system/xstore/xstore_members.md)
