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

# XStoreQueryProductForPackageAsync

> XStoreQueryProductForPackageAsync

# XStoreQueryProductForPackageAsync

检索指定包的商店产品信息。

## 语法

```cpp theme={null}
HRESULT XStoreQueryProductForPackageAsync(  
         const XStoreContextHandle storeContextHandle,  
         XStoreProductKind productKinds,  
         const char* packageIdentifier,  
         XAsyncBlock* async  
)  
```

### 参数

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

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

*productKinds*   \_In\_\
类型：[XStoreProductKind](https://docs.xbox.com/zh-CN/reference/system/xstore/enums/xstoreproductkind.md)

要查找的产品类型。

*packageIdentifier*   \_In\_z\_\
类型：char\*

唯一标识商店包的字符串。有关包标识符的详细信息，请参阅[管理和许可可下载内容 (DLC)](https://docs.xbox.com/zh-CN/publishing/xstore-commerce/xstore-dlc.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 成功或错误代码。

## 备注

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

以下代码片段展示了检索包产品信息的示例。

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

    HRESULT hr = XStoreQueryProductForPackageResult(
        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 QueryProductForPackage(XStoreContextHandle storeContextHandle, const char* packageIdentifier)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->callback = QueryProductForPackageCallback;

    XStoreProductKind allProductKinds =
        XStoreProductKind::Consumable |
        XStoreProductKind::Durable |
        XStoreProductKind::Game |
        XStoreProductKind::Pass |
        XStoreProductKind::UnmanagedConsumable;

    HRESULT hr = XStoreQueryProductForPackageAsync(
        storeContextHandle,
        allProductKinds,
        packageIdentifier,
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to get product for package: 0x%x\r\n", hr);
        return;
    }
}


```

## 要求

**头文件：** XStore.h（包含在 XGameRuntime.h 中）

**库：** xgameruntime.lib

**支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## 另请参阅

[XStore](https://docs.xbox.com/zh-CN/reference/system/xstore/xstore_members.md)\
[XStoreQueryProductForPackageResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryproductforpackageresult.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

- [XStoreQueryProductForPackageResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryproductforpackageresult.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)
- [XStoreQueryAssociatedProductsForStoreIdResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorequeryassociatedproductsforstoreidresult.md)
- [XStoreProductKind](https://docs.xbox.com/zh-CN/reference/system/xstore/enums/xstoreproductkind.md)
