> ## 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](/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 成功或錯誤碼。

## 備註

> !\[NOTE] 此作業不會在預期的購買之後觸發項目的下載或安裝。如果您想要下載並安裝此內容，建議在購買成功後呼叫 [XStoreDownloadAndInstallPackagesAsync](/zh-TW/reference/system/xstore/functions/xstoredownloadandinstallpackagesasync)。系統不會再向使用者顯示其他提示。

> !\[NOTE] 在 PC 上，購買成功後顯示的購買確認對話方塊頂端會有關閉按鈕 \[X]。選取此按鈕而非 \[確定]，會導致 `XStoreShowPurchaseUIResult` 傳回 E\_ABORT，這可能不是您想要的結果。這是以此方式關閉任何對話方塊時的標準 Windows 行為。

若要擷取此函式的結果，請在呼叫此函式之後呼叫 [XStoreShowPurchaseUIResult](/zh-TW/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)
* [基本商店作業](/zh-TW/publishing/xstore-commerce/xstore-basic-operations)
* [管理可下載內容 (DLC) 並授權](/zh-TW/publishing/xstore-commerce/xstore-dlc)
* [XStore 開發疑難排解](/zh-TW/publishing/xstore-commerce/xstore-troubleshooting)

## 另請參閱

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


## Related topics

- [XStoreShowPurchaseUIAsync](/ja-jp/reference/system/xstore/functions/xstoreshowpurchaseuiasync.md)
- [XStoreShowPurchaseUIResult](/reference/system/xstore/functions/xstoreshowpurchaseuiresult.md)
