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

# XStoreShowGiftingUIAsync

> XStoreShowGiftingUIAsync

# XStoreShowGiftingUIAsync

启动 UI 覆盖以将指定产品作为礼物为另一用户购买。将提示当前用户输入有关礼物收件人的信息，并引导其完成购买流程。

## 语法

```cpp theme={null}
HRESULT XStoreShowGiftingUIAsync(  
         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 成功或错误代码。

## 备注

要作为礼物购买的产品必须配置为支持礼物购买。要检索支持礼物赠送的产品列表，请调用 [XStoreQueryProductsAsync](/reference/system/xstore/functions/xstorequeryproductsasync)，并将 `actionFilters` 参数设置为 `"Gift"`。

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

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

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

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

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

    HRESULT hr = XStoreShowGiftingUIAsync(
        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 主机

## 另请参阅

[XStore](/reference/system/xstore/xstore_members)\
[XStoreShowGiftingUIResult](/reference/system/xstore/functions/xstoreshowgiftinguiresult)


## Related topics

- [XStoreShowGiftingUIResult](/zh-CN/reference/system/xstore/functions/xstoreshowgiftinguiresult.md)
- [XStore](/zh-CN/reference/system/xstore/xstore_members.md)
- [XStoreShowPurchaseUIAsync](/zh-CN/reference/system/xstore/functions/xstoreshowpurchaseuiasync.md)
- [XStoreShowRateAndReviewUIAsync](/zh-CN/reference/system/xstore/functions/xstoreshowrateandreviewuiasync.md)
- [XStoreShowRedeemTokenUIAsync](/zh-CN/reference/system/xstore/functions/xstoreshowredeemtokenuiasync.md)
