XStoreShowPurchaseUIAsync
开始指定产品的购买 UI 覆盖。
语法
HRESULT XStoreShowPurchaseUIAsync(
const XStoreContextHandle storeContextHandle,
const char* storeId,
const char* name,
const char* extendedJsonData,
XAsyncBlock* async
)
参数
storeContextHandle _In_
类型:XStoreContextHandle
XStoreCreateContext 返回的用户的应用商店上下文句柄。
storeId _In_z_
类型:char*
要购买的产品 ID。
name _In_opt_z_
类型:char*
要购买的产品名称。
extendedJsonData _In_opt_z_
类型:char*
转给购买流程的 json blob。 允许插入自定义市场活动 ID,以便您可以跟踪如何启动购买。
async _Inout_
类型:XAsyncBlock*
用于定义正在进行的异步工作的 XAsyncBlock。 XAsyncBlock 可用于轮询调用的状态和检索调用结果。 有关详细信息,请参阅 XAsyncBlock。
返回值
类型:HRESULT
HRESULT 成功或错误代码。
备注
![注意]此操作不会在预期购买后触发项的下载或安装。 如果你想下载或安装此内容,建议你在成功购买后呼叫XStoreDownloadAndInstallPackagesAsync. 用户不会收到附加提示。
![注意]在电脑上,购买成功后显示的购买确认对话框顶部将有一个关闭按钮 [X]。 选择此选项而不是“确定”将导致E_ABORT返回到
XStoreShowPurchaseUIResult
,这可能不是所需的。 这是以这种方式关闭任何对话框时的标准 Windows 行为。
要检索此函数的结果,请在调用此函数后调用 XStoreShowPurchaseUIResult。 仅当用户已选择购买某物时才调用此函数,并将导致系统显示模式购买对话框,该对话框在进程外处理付款信息和用户确认。
以下代码片段显示了请求购买特定商店产品的示例。
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 主机