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

# XStoreQueryProductsAsync

> XStoreQueryProductsAsync

# XStoreQueryProductsAsync

傳回與目前遊戲相關聯之指定產品的清單資訊，無論這些產品是否可在遊戲內購買。

## 語法

```cpp theme={null}
HRESULT XStoreQueryProductsAsync(  
         const XStoreContextHandle storeContextHandle,  
         XStoreProductKind productKinds,  
         const char** storeIds,  
         size_t storeIdsCount,  
         const char** actionFilters,  
         size_t actionFiltersCount,  
         XAsyncBlock* async  
)  
```

### 參數

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

由 [XStoreCreateContext](/zh-TW/reference/system/xstore/functions/xstorecreatecontext) 傳回的使用者市集內容控制代碼。

*productKinds*   \_In\_\
類型：[XStoreProductKind](/zh-TW/reference/system/xstore/enums/xstoreproductkind)

要傳回的產品類型。

*storeIds*   \_In\_z\_count\_(storeIdsCount)\
類型：char\*\*

要擷取之產品的市集識別碼。

*storeIdsCount*   \_In\_\
類型：size\_t

**storeIds** 清單中的產品數目。
此數目不應超過 100。

*actionFilters*   \_In\_opt\_z\_count\_(actionFiltersCount)\
類型：char\*\*

依據產品文件中儲存的某個動作來限制結果。
根據預設，此 API 會傳回所有產品，即使產品無法購買也一樣，但您可以使用動作篩選條件來限制結果。
例如，如果您只想要可購買的產品，請使用 "Purchase"；如果您只想要可授權的產品，請使用 "License"。
其他動作篩選條件包括 "Fulfill"、"Browse"、"Curate"、"Details" 和 "Redeem"。

*actionFiltersCount*   \_In\_\
類型：size\_t

**actionFilters** 中的篩選條件數目。

*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 成功或錯誤碼。

## 備註

呼叫 [XStoreQueryProductsResult](/zh-TW/reference/system/xstore/functions/xstorequeryproductsresult) 以擷取清單資訊和此函式的執行結果。

如果您在要求中提供超過 100 個 storeID，此 API 就會失敗。
如果您使用的是大型目錄，請將每個查詢限制在少於 100 個產品。

若要取得玩家可在目前遊戲內購買之所有產品的詳細資料，請改用 [XStoreQueryAssociatedProductsAsync](/zh-TW/reference/system/xstore/functions/xstorequeryassociatedproductsasync)。

下列程式碼片段示範擷取與目前遊戲相關聯之指定產品清單資訊的範例。

```cpp theme={null}

void ProcessResults(XStoreProductQueryHandle queryHandle)
{
    HRESULT hr = XStoreEnumerateProductsQuery(
        queryHandle,
        nullptr,
        EnumerateProductsQueryCallback);

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

    XStoreCloseProductsQueryHandle(queryHandle);
}

void CALLBACK QueryProductsCallback(XAsyncBlock* asyncBlock)
{
    XStoreProductQueryHandle queryHandle = nullptr;

    HRESULT hr = XStoreQueryProductsResult(
        asyncBlock,
        &queryHandle);

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

     ProcessResults(queryHandle);
}

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

    asyncBlock->callback = QueryProductsCallback;

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

    const char* storeIds[] =
    {
        "9YYYYYYYYYYY",
        "9ZZZZZZZZZZZ",
    };

    // This is only needed if you want to restrict to items that are currently purchasable.
    // If you want items that have been sold in the past,
    // but are no longer available for purchase, then
    // pass in nullptr or an empty array for the actionFilters.
    const char* actionFilters[] =
    {
        "Purchase"
    };

    HRESULT hr = XStoreQueryProductsAsync(
        storeContextHandle,
        allProductKinds,
        storeIds,
        ARRAYSIZE(storeIds),
        actionFilters,
        ARRAYSIZE(actionFilters),
        asyncBlock.get());

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

```

## 需求

**標頭：** XStore.h (包含在 XGameRuntime.h 中)

**程式庫：** xgameruntime.lib

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 概念文件

* [基本市集作業](/zh-TW/publishing/xstore-commerce/xstore-basic-operations)
* [授與玩家附加元件內容的存取權](/zh-TW/publishing/xstore-commerce/xstore-granting-access)
* [Microsoft Store API 的細微速率限制](/zh-TW/publishing/xstore-commerce/xstore-fgrl)

## 另請參閱

[XStore](/zh-TW/reference/system/xstore/xstore_members)
[XStoreQueryProductsResult](/zh-TW/reference/system/xstore/functions/xstorequeryproductsresult)\
[XStoreQueryAssociatedProductsAsync](/zh-TW/reference/system/xstore/functions/xstorequeryassociatedproductsasync)\
[XStoreQueryEntitledProductsAsync](/zh-TW/reference/system/xstore/functions/xstorequeryentitledproductsasync)\
[XStoreQueryProductsAsync](/zh-TW/reference/system/xstore/functions/xstorequeryproductsasync)\
[XStoreQueryProductForCurrentGameAsync](/zh-TW/reference/system/xstore/functions/xstorequeryproductforcurrentgameasync)\
[XStoreQueryProductForPackageAsync](/zh-TW/reference/system/xstore/functions/xstorequeryproductforpackageasync)\
[基本市集作業](/zh-TW/publishing/xstore-commerce/xstore-basic-operations)\
[授與玩家附加元件內容的存取權](/zh-TW/publishing/xstore-commerce/xstore-granting-access)


## Related topics

- [XStoreQueryProductsAsync](/reference/system/xstore/functions/xstorequeryproductsasync.md)
- [XStoreQueryProductsResult](/reference/system/xstore/functions/xstorequeryproductsresult.md)
