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

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](/pt-BR/reference/system/xstore/functions/xstorecreatecontext).

*productKinds*   \_In\_\
Tipo: [XStoreProductKind](/pt-BR/reference/system/xstore/enums/xstoreproductkind)

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\*](/pt-BR/reference/system/xasync/structs/xasyncblock)

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

### Valor retornado

Tipo: HRESULT

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

## Comentários

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

<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](/pt-BR/reference/system/xstore/functions/xstorequeryassociatedproductsasync).

  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](/pt-BR/reference/system/xstore/functions/xstorequeryassociatedproductsasync#paging).
</Note>

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](/pt-BR/publishing/xstore-commerce/xstore-basic-operations)
* [Como usar um durável sem um pacote](/pt-BR/publishing/xstore-commerce/xstore-dwob)
* [Conceder aos jogadores acesso ao conteúdo de complementos](/pt-BR/publishing/xstore-commerce/xstore-granting-access)
* [Visão geral dos sistemas de comércio do GDK](/pt-BR/publishing/xstore-commerce/xstore-overview)
* [Limitação de taxa refinada para APIs da Microsoft Store](/pt-BR/publishing/xstore-commerce/xstore-fgrl)

## Confira também

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


## Related topics

- [XStoreQueryEntitledProductsAsync](/reference/system/xstore/functions/xstorequeryentitledproductsasync.md)
- [XStoreQueryEntitledProductsResult](/reference/system/xstore/functions/xstorequeryentitledproductsresult.md)
- [XStoreQueryProductsAsync](/reference/system/xstore/functions/xstorequeryproductsasync.md)
- [XStoreQueryProductForPackageAsync](/reference/system/xstore/functions/xstorequeryproductforpackageasync.md)
