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

# XStoreQueryEntitledProductsAsync

> XStoreQueryEntitledProductsAsync

# XStoreQueryEntitledProductsAsync

現在のゲームに関連する、ユーザーに権利のあるすべての製品のストア情報を返します。

## 構文

```cpp theme={null}
HRESULT XStoreQueryEntitledProductsAsync(  
         const XStoreContextHandle storeContextHandle,  
         XStoreProductKind productKinds,  
         uint32_t maxItemsToRetrievePerPage,  
         XAsyncBlock* async  
)  
```

### パラメーター

*storeContextHandle*   \_In\_\
Type: XStoreContextHandle

[XStoreCreateContext](/ja-jp/reference/system/xstore/functions/xstorecreatecontext.md) から返される、ユーザーのストア コンテキスト ハンドル。

*productKinds*   \_In\_\
Type: [XStoreProductKind](/ja-jp/reference/system/xstore/enums/xstoreproductkind.md)

クエリする製品の種類。

*maxItemsToRetrievePerPage*   \_In\_\
Type: uint32\_t

1 ページあたりに取得する項目の最大数。
1 ページあたりに返される項目の数は、0 から `maxItemsToRetrievePerPage` まで異なる場合があります。

*async*   \_Inout\_\
Type: [XAsyncBlock\*](/ja-jp/reference/system/xasync/structs/xasyncblock.md)

実行中の非同期処理を定義する [XAsyncBlock](/ja-jp/reference/system/xasync/structs/xasyncblock.md)。
[XAsyncBlock](/ja-jp/reference/system/xasync/structs/xasyncblock.md) は、呼び出しの状態のポーリングと呼び出し結果の取得に使用できます。
詳細については、[XAsyncBlock](/ja-jp/reference/system/xasync/structs/xasyncblock.md) を参照してください。

### 戻り値

Type: HRESULT

成功した場合は S\_OK。それ以外の場合はエラー コードが返されます。

## 解説

この関数のストア製品情報と実行結果を取得するには、[XStoreQueryEntitledProductsResult](/ja-jp/reference/system/xstore/functions/xstorequeryentitledproductsresult.md) を呼び出します。
`XStoreQueryEntitledProductsAsync` のコールバック関数内で [XStoreQueryEntitledProductsResult](/ja-jp/reference/system/xstore/functions/xstorequeryentitledproductsresult.md) を実行します。
結果には、[XStoreEnumerateProductsQuery](/ja-jp/reference/system/xstore/functions/xstoreenumerateproductsquery.md) を呼び出して列挙できる `XStoreProductQueryHandle` が含まれます。

> [!NOTE]
>
> プレイヤーが権利を持っている項目が多いほど、この API の戻り時間は長くなります。
>
> この API は [XStoreQueryAssociatedProductsAsync](/ja-jp/reference/system/xstore/functions/xstorequeryassociatedproductsasync.md) で説明されているのと同じページング パターンをサポートします。
>
> ページングは、サンドボックスと RETAIL の間で動作が異なる場合があります。ページング実装を検証し、リリース前に必ず RETAIL でテストしてください。
>
> 詳細については、[ページング](/ja-jp/reference/system/xstore/functions/xstorequeryassociatedproductsasync.md#paging)を参照してください。

このクエリが返す製品の数を事前に知ることはできません。

次のコード スニペットは、現在のゲームに関連するコンテンツに対するユーザーの権利をクエリする例を示しています。
結果は複数のページにわたって処理されます。

```cpp theme={null}
struct QueryContext
{
    uint32_t count = 0;  // used to accumulate count of products returned across pages
    XStoreProductQueryHandle handle = nullptr;  // handle to reuse for paged operations
};

void CleanupProductQuery(XAsyncBlock* async)
{
    if (!async) return;

    auto* ctx = static_cast<QueryContext*>(async->context);
    if (ctx)
    {
        if (ctx->handle)
        {
            XStoreCloseProductsQueryHandle(ctx->handle);
            ctx->handle = nullptr;
        }

        delete ctx;
        async->context = nullptr;
    }

    delete async;
}

bool CALLBACK ProductEnumerationCallback(const XStoreProduct* product, void* context)
{
    // Use result of query
    auto* ctx = static_cast<QueryContext*>(context);

    // Empty results are possible and should be skipped
    if (product)
    {
        printf("%s %s %u\n", product->title, product->storeId, product->productKind);
        ctx->count++;
    }

    return true;
}

void CALLBACK QueryEntitledProductsCallback(XAsyncBlock* async)
{
    auto* ctx = static_cast<QueryContext*>(async->context);

    HRESULT hr = XStoreQueryEntitledProductsResult(async, &ctx->handle);
    if (FAILED(hr)) { CleanupProductQuery(async); return; }

    hr = XStoreEnumerateProductsQuery(ctx->handle, ctx, ProductEnumerationCallback);
    if (FAILED(hr)) { CleanupProductQuery(async); return; }

    if (XStoreProductsQueryHasMorePages(ctx->handle))
    {
        QueryNextPage(async);
        return;
    }

    printf("Enumeration complete, %u entitled products found\n", ctx->count);
    CleanupProductQuery(async);
}

void QueryEntitledProducts(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle)
{
    auto async = new XAsyncBlock{};
    async->context = new QueryContext{ 0, nullptr };
    async->queue = taskQueueHandle; 
    async->callback = QueryEntitledProductsCallback; 
 
    XStoreProductKind typeFilter = 
        XStoreProductKind::Consumable | 
        XStoreProductKind::Durable | 
        XStoreProductKind::Game |
        XStoreProductKind::Pass |
        XStoreProductKind::UnmanagedConsumable;
 
    HRESULT hr = XStoreQueryEntitledProductsAsync( 
        storeContextHandle, 
        typeFilter, 
        25,           // Products per page (25 is a good default, can set lower to verify paging in sandbox)
        async);

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

// In RETAIL, content will be returned across multiple pages.
// Paging is not complete until XStoreProductsQueryHasMorePages returns false.
void QueryNextPage(XAsyncBlock *async)
{
    async->callback = [](XAsyncBlock* async)
    {
        auto* ctx = static_cast<QueryContext*>(async->context);

        XStoreProductQueryHandle next = nullptr;
        HRESULT hr = XStoreProductsQueryNextPageResult(async, &next);
        if (FAILED(hr)) { CleanupProductQuery(async); return; }

        // Safe swap: avoids leaks if 'next' is a new handle, avoids double-close if identical
        if (next && next != ctx->handle)
        {
            if (ctx->handle) XStoreCloseProductsQueryHandle(ctx->handle);
            ctx->handle = next;
        }
        else
        {
            ctx->handle = next; // covers null or same-handle cases
        }

        hr = XStoreEnumerateProductsQuery(ctx->handle, ctx, ProductEnumerationCallback);
        if (FAILED(hr)) { CleanupProductQuery(async); return; }

        if (XStoreProductsQueryHasMorePages(ctx->handle))
        {
            QueryNextPage(async);
            return;
        }

        printf("Enumeration complete, %u entitled products found\n", ctx->count);
        CleanupProductQuery(async);
    };

    auto* ctx = static_cast<QueryContext*>(async->context);
    HRESULT hr = XStoreProductsQueryNextPageAsync(ctx->handle, async);
    if (FAILED(hr))
    {
        CleanupProductQuery(async);
    }
}

```

## 要件

**ヘッダー:** 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)
* [ストアの基本操作](/ja-jp/publishing/xstore-commerce/xstore-basic-operations.md)
* [パッケージなしの永続型を使用する方法](/ja-jp/publishing/xstore-commerce/xstore-dwob.md)
* [プレイヤーにアドオン コンテンツへのアクセス権を付与する](/ja-jp/publishing/xstore-commerce/xstore-granting-access.md)
* [GDK コマース システムの概要](/ja-jp/publishing/xstore-commerce/xstore-overview.md)
* [Microsoft Store API のきめ細かなレート制限](/ja-jp/publishing/xstore-commerce/xstore-fgrl.md)

## 関連項目

[XStore](/ja-jp/reference/system/xstore/xstore_members.md)\
[XStoreQueryEntitledProductsResult](/ja-jp/reference/system/xstore/functions/xstorequeryentitledproductsresult.md)
[XStoreQueryAssociatedProductsAsync](/ja-jp/reference/system/xstore/functions/xstorequeryassociatedproductsasync.md)\
[XStoreQueryEntitledProductsAsync](/ja-jp/reference/system/xstore/functions/xstorequeryentitledproductsasync.md)\
[XStoreQueryProductsAsync](/ja-jp/reference/system/xstore/functions/xstorequeryproductsasync.md)\
[XStoreQueryProductForCurrentGameAsync](/ja-jp/reference/system/xstore/functions/xstorequeryproductforcurrentgameasync.md)\
[XStoreQueryProductForPackageAsync](/ja-jp/reference/system/xstore/functions/xstorequeryproductforpackageasync.md)\
[ストアの基本操作](/ja-jp/publishing/xstore-commerce/xstore-basic-operations.md)\
[プレイヤーにアドオン コンテンツへのアクセス権を付与する](/ja-jp/publishing/xstore-commerce/xstore-granting-access.md)


## Related topics

- [XStoreQueryEntitledProductsResult](/ja-jp/reference/system/xstore/functions/xstorequeryentitledproductsresult.md)
- [XStoreQueryProductForPackageAsync](/ja-jp/reference/system/xstore/functions/xstorequeryproductforpackageasync.md)
- [XStoreQueryProductForPackageResult](/ja-jp/reference/system/xstore/functions/xstorequeryproductforpackageresult.md)
- [XStoreQueryProductForCurrentGameAsync](/ja-jp/reference/system/xstore/functions/xstorequeryproductforcurrentgameasync.md)
- [XStoreQueryAssociatedProductsForStoreIdResult](/ja-jp/reference/system/xstore/functions/xstorequeryassociatedproductsforstoreidresult.md)
