> ## 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](/zh-TW/reference/system/xstore/functions/xstorecreatecontext) 傳回的使用者市集內容控制代碼。

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

要購買作為禮物之產品的識別碼。**注意**：此產品必須設定為支援禮物購買。

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

要購買作為禮物之產品的名稱。

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

交給禮物購買流程的 JSON Blob。可讓您插入自訂行銷活動識別碼，以便追蹤購買是如何開始的。

*async*   \_Inout\_\
類型：[XAsyncBlock\*](/zh-TW/reference/system/xasync/structs/xasyncblock)

定義正在進行之非同步工作的 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock)。[XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock) 可用來輪詢呼叫的狀態並擷取呼叫結果。如需詳細資訊，請參閱 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock)。

### 傳回值

類型：HRESULT

HRESULT 成功或錯誤碼。

## 備註

要購買作為禮物的產品必須設定為支援禮物購買。若要擷取支援贈送禮物的產品清單，請在 `actionFilters` 參數設定為 `"Gift"` 的情況下呼叫 [XStoreQueryProductsAsync](/zh-TW/reference/system/xstore/functions/xstorequeryproductsasync)。

若要擷取此函式的結果，請在呼叫此函式之後呼叫 [XStoreShowGiftingUIResult](/zh-TW/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](/zh-TW/reference/system/xstore/xstore_members)\
[XStoreShowGiftingUIResult](/zh-TW/reference/system/xstore/functions/xstoreshowgiftinguiresult)


## Related topics

- [XStoreShowGiftingUIAsync](/reference/system/xstore/functions/xstoreshowgiftinguiasync.md)
- [XStoreShowGiftingUIResult](/reference/system/xstore/functions/xstoreshowgiftinguiresult.md)
