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

# XStoreQueryEntitledProductsAsync

> XStoreQueryEntitledProductsAsync

# XStoreQueryEntitledProductsAsync

Retorna informações da loja para todos os produtos relacionados ao jogo atual aos quais o usuário tem direito.

## Sintaxe

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

### Parâmetros

*storeContextHandle*   \_In\_\
Tipo: XStoreContextHandle

O identificador de contexto da loja para o usuário retornado por [XStoreCreateContext](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorecreatecontext.md).

*productKinds*   \_In\_\
Tipo: [XStoreProductKind](https://docs.xbox.com/pt-BR/reference/system/xstore/enums/xstoreproductkind.md)

O tipo de produtos a serem consultados.

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

Número máximo de itens a serem recuperados por página.
O número de itens retornados por página pode variar de 0 a `maxItemsToRetrievePerPage`.

*async*   \_Inout\_\
Tipo: [XAsyncBlock\*](https://docs.xbox.com/pt-BR/reference/system/xasync/structs/xasyncblock.md)

Um [XAsyncBlock](https://docs.xbox.com/pt-BR/reference/system/xasync/structs/xasyncblock.md) que define o trabalho assíncrono que está sendo realizado.
O [XAsyncBlock](https://docs.xbox.com/pt-BR/reference/system/xasync/structs/xasyncblock.md) pode ser usado para sondar o status da chamada e recuperar os resultados da chamada.
Para obter mais informações, consulte [XAsyncBlock](https://docs.xbox.com/pt-BR/reference/system/xasync/structs/xasyncblock.md).

### Valor retornado

Tipo: HRESULT

S\_OK em caso de sucesso; caso contrário, retorna um código de erro.

## Comentários

Chame [XStoreQueryEntitledProductsResult](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryentitledproductsresult.md) para recuperar as informações do produto da loja e o resultado da execução desta função.
Execute [XStoreQueryEntitledProductsResult](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryentitledproductsresult.md) na função de retorno de chamada de `XStoreQueryEntitledProductsAsync`.
O resultado contém um `XStoreProductQueryHandle` que você pode enumerar chamando [XStoreEnumerateProductsQuery](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstoreenumerateproductsquery.md).

> [!NOTE]
>
> Quanto mais itens um jogador tiver direito, mais tempo esta API poderá levar para retornar.
>
> Esta API oferece suporte ao mesmo padrão de paginação descrito em [XStoreQueryAssociatedProductsAsync](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryassociatedproductsasync.md).
>
> A paginação pode se comportar de forma diferente entre áreas restritas e RETAIL. Verifique sua implementação de paginação e não deixe de testar em RETAIL antes do lançamento.
>
> Para obter mais informações, consulte [Paginação](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryassociatedproductsasync.md#paging).

Não é possível saber antecipadamente o número de produtos retornados por esta consulta.

O snippet de código a seguir fornece um exemplo de consulta dos direitos de um usuário a conteúdo relacionado ao jogo atual.
Os resultados são processados em várias páginas.

```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);
    }
}

```

## Requisitos

**Cabeçalho:** XStore.h (incluído em XGameRuntime.h)

**Biblioteca:** xgameruntime.lib

**Plataformas com suporte:** Windows, consoles da família XBOX One e consoles XBOX Series

## Documentação conceitual

* [Implementar compras no jogo](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/pc-dev/tutorials/pc-e2e-guide/e2e-services/e2e-in-game-purchases)
* [Operações básicas da loja](https://docs.xbox.com/pt-BR/publishing/xstore-commerce/xstore-basic-operations.md)
* [Como usar um durável sem um pacote](https://docs.xbox.com/pt-BR/publishing/xstore-commerce/xstore-dwob.md)
* [Conceder aos jogadores acesso ao conteúdo de complementos](https://docs.xbox.com/pt-BR/publishing/xstore-commerce/xstore-granting-access.md)
* [Visão geral dos sistemas de comércio do GDK](https://docs.xbox.com/pt-BR/publishing/xstore-commerce/xstore-overview.md)
* [Limitação de taxa refinada para APIs da Microsoft Store](https://docs.xbox.com/pt-BR/publishing/xstore-commerce/xstore-fgrl.md)

## Confira também

[XStore](https://docs.xbox.com/pt-BR/reference/system/xstore/xstore_members.md)\
[XStoreQueryEntitledProductsResult](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryentitledproductsresult.md)
[XStoreQueryAssociatedProductsAsync](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryassociatedproductsasync.md)\
[XStoreQueryEntitledProductsAsync](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryentitledproductsasync.md)\
[XStoreQueryProductsAsync](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryproductsasync.md)\
[XStoreQueryProductForCurrentGameAsync](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryproductforcurrentgameasync.md)\
[XStoreQueryProductForPackageAsync](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryproductforpackageasync.md)\
[Operações básicas da loja](https://docs.xbox.com/pt-BR/publishing/xstore-commerce/xstore-basic-operations.md)\
[Conceder aos jogadores acesso ao conteúdo de complementos](https://docs.xbox.com/pt-BR/publishing/xstore-commerce/xstore-granting-access.md)


## Related topics

- [XStoreQueryEntitledProductsResult](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryentitledproductsresult.md)
- [XStoreQueryProductsAsync](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryproductsasync.md)
- [XStoreQueryProductForPackageAsync](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryproductforpackageasync.md)
- [XStoreQueryProductForPackageResult](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryproductforpackageresult.md)
- [XStoreQueryProductsResult](https://docs.xbox.com/pt-BR/reference/system/xstore/functions/xstorequeryproductsresult.md)
