> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XStoreQueryProductForCurrentGameAsync

> XStoreQueryProductForCurrentGameAsync

# XStoreQueryProductForCurrentGameAsync

提供当前正在运行的游戏的商店产品信息、其 sku 和可用性以及其他元数据。

## 语法

```cpp theme={null}
HRESULT XStoreQueryProductForCurrentGameAsync(  
         const XStoreContextHandle storeContextHandle,  
         XAsyncBlock* async  
)  
```

### 参数

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

[XStoreCreateContext](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorecreatecontext.md) 为用户返回的商店上下文句柄。

*async*   \_Inout\_\
类型：[XAsyncBlock\*](https://docs.xbox.com/zh-CN/reference/system/xasync/structs/xasyncblock.md)

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

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

## 备注

要检索商店产品信息以及此函数调用的执行结果，请在调用此函数之后调用 [XStoreQueryProductForCurrentGameResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryproductforcurrentgameresult.md)。

以下代码片段展示了检索当前正在运行的游戏的商店产品信息的示例。

```cpp theme={null}
void CALLBACK QueryProductForCurrentGameCallback(XAsyncBlock* asyncBlock)
{
    XStoreProductQueryHandle queryHandle = nullptr;

    HRESULT hr = XStoreQueryProductForCurrentGameResult(
        asyncBlock,
        &queryHandle);

    if (FAILED(hr))
    {
        printf("Failed retrieve the product query handle: 0x%x\r\n", hr);
        XStoreCloseProductsQueryHandle(queryHandle);
        return;
    }

    // Use result of query

     XStoreCloseProductsQueryHandle(queryHandle);
}

void QueryProductForCurrentGame(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;

    asyncBlock->callback = QueryProductForCurrentGameCallback;

    HRESULT hr = XStoreQueryProductForCurrentGameAsync(
        storeContextHandle,
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to get product for current game: 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://docs.xbox.com/zh-CN/publishing/xstore-commerce/xstore-basic-operations.md)

## 另请参阅

[XStore](https://docs.xbox.com/zh-CN/reference/system/xstore/xstore_members.md)\
[XStoreQueryProductForCurrentGameResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryproductforcurrentgameresult.md)\
[XStoreQueryAssociatedProductsAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryassociatedproductsasync.md)\
[XStoreQueryEntitledProductsAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryentitledproductsasync.md)\
[XStoreQueryProductsAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryproductsasync.md)\
[XStoreQueryProductForCurrentGameAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryproductforcurrentgameasync.md)\
[XStoreQueryProductForPackageAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryproductforpackageasync.md)


## Related topics

- [XStoreQueryProductForCurrentGameResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryproductforcurrentgameresult.md)
- [XStoreQueryProductForPackageAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryproductforpackageasync.md)
- [XStoreQueryProductsAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryproductsasync.md)
- [XStoreQueryProductForPackageResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryproductforpackageresult.md)
- [XStoreQueryAssociatedProductsForStoreIdResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryassociatedproductsforstoreidresult.md)
