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

# XStoreQueryGameAndDlcPackageUpdatesAsync

> XStoreQueryGameAndDlcPackageUpdatesAsync

# XStoreQueryGameAndDlcPackageUpdatesAsync

Récupère la liste des mises à jour disponibles pour le package du jeu et pour tout DLC associé ou package compatible avec un hub, qui peut ensuite être utilisée pour télécharger et installer ces mises à jour.

## Syntaxe

```cpp theme={null}
HRESULT XStoreQueryGameAndDlcPackageUpdatesAsync(  
         const XStoreContextHandle storeContextHandle,  
         XAsyncBlock* async  
)  
```

### Paramètres

*storeContextHandle*   \_In\_\
Type : XStoreContextHandle

Handle de contexte du Store pour l'utilisateur, retourné par [XStoreCreateContext](/fr-CA/reference/system/xstore/functions/xstorecreatecontext).

*async*   \_Inout\_\
Type : [XAsyncBlock\*](/fr-CA/reference/system/xasync/structs/xasyncblock)

[XAsyncBlock](/fr-CA/reference/system/xasync/structs/xasyncblock) définissant le travail asynchrone en cours. Le [XAsyncBlock](/fr-CA/reference/system/xasync/structs/xasyncblock) peut être utilisé pour interroger l'état de l'appel et récupérer les résultats de l'appel. Pour plus d'informations, consultez [XAsyncBlock](/fr-CA/reference/system/xasync/structs/xasyncblock).

### Valeur de retour

Type : HRESULT

Code de réussite ou d'erreur HRESULT.

## Remarques

Pour récupérer la liste des mises à jour disponibles ainsi que le résultat d'exécution de cette fonction, appelez [XStoreQueryGameAndDlcPackageUpdatesResult](/fr-CA/reference/system/xstore/functions/xstorequerygameanddlcpackageupdatesresult) après avoir appelé cette fonction. Pour obtenir le nombre de mises à jour à récupérer, appelez [XStoreQueryGameAndDlcPackageUpdatesResultCount](/fr-CA/reference/system/xstore/functions/xstorequerygameanddlcpackageupdatesresultcount) après avoir appelé cette fonction. La fonction de nombre de résultats est importante, car elle vous permet de déterminer la taille appropriée du tableau à passer à la fonction de résultat.

| Contexte d'appel | Résultat |
| - | - |
| Hub de jeux de franchise | Le hub de jeux de franchise lui-même, tout jeu compatible avec un hub qui en dépend, ainsi que tout DLC ou extension associé à l'un des jeux compatibles avec un hub ou au hub de jeux de franchise lui-même. |
| Autre jeu | Le jeu lui-même ainsi que les DLC et extensions qui lui sont associés. |

L'extrait de code suivant montre un exemple de récupération des mises à jour du jeu et des mises à jour facultatives pour le package en cours.

```cpp theme={null}
struct UpdateContext
{
    XStoreContextHandle storeContextHandle;
    XTaskQueueHandle taskQueueHandle;
    bool downloadOnly;
};

void CALLBACK DownloadAndInstallPackageUpdatesCallback(XAsyncBlock* asyncBlock)
{
    HRESULT hr = XStoreDownloadAndInstallPackageUpdatesResult(asyncBlock);

    if (FAILED(hr))
    {
        printf("Failed download and install package updates: 0x%x\r\n", hr);
        return;
    }
}

void CALLBACK DownloadPackageUpdatesCallback(XAsyncBlock* asyncBlock)
{
    HRESULT hr = XStoreDownloadPackageUpdatesResult(asyncBlock);

    if (FAILED(hr))
    {
        printf("Failed download package updates: 0x%x\r\n", hr);
        return;
    }
}

void CALLBACK QueryGameAndDlcPackageUpdatesCallback(XAsyncBlock* asyncBlock)
{
    UpdateContext* updateContext = reinterpret_cast<UpdateContext*>(asyncBlock->context);
    uint32_t count;

    HRESULT hr = XStoreQueryGameAndDlcPackageUpdatesResultCount(
        asyncBlock,
        &count);

    if (FAILED(hr))
    {
        printf("Failed retrieve the game and dlc update count: 0x%x\r\n", hr);
        delete updateContext;
        return;
    }

    printf("Number of updates: %d", count);

    if (count > 0)
    {
        XStorePackageUpdate* updates = new XStorePackageUpdate[count];
        hr = XStoreQueryGameAndDlcPackageUpdatesResult(
            asyncBlock,
            count,
            &updates);

        if (FAILED(hr))
        {
            delete[] updates;
            delete updateContext;
            printf("Failed retrieve the game and dlc updates: 0x%x\r\n", hr);
            return;
        }

        auto packageIdentifiers = new char[count][XPACKAGE_IDENTIFIER_MAX_LENGTH];
        for (uint32_t index = 0; index < count; index++)
        {
            printf("packageIdentifier: %s\r\n", updates[index].packageIdentifier);
            printf("isMandatory      : %s\r\n", updates[index].isMandatory ? "true" : "false");

            memcpy(&packageIdentifiers[index], updates[index].packageIdentifier, XPACKAGE_IDENTIFIER_MAX_LENGTH);
        }

        delete[] updates;

        auto downloadAsyncBlock = std::make_unique<XAsyncBlock>();
        ZeroMemory(downloadAsyncBlock.get(), sizeof(*downloadAsyncBlock));
        downloadAsyncBlock->queue = updateContext->taskQueueHandle;
        downloadAsyncBlock->context = updateContext;

        if (updateContext->downloadOnly)
        {
            // NOTE: This can be used instead to only perform the download.
            // This is helpful if you wish to download in the background
            // while the player continues to play. Once the download is completed,
            // you could then warn the user and call XStoreDownloadAndInstallPackageUpdatesAsync
            // to trigger the game to update which may close the game.

            downloadAsyncBlock->callback = DownloadPackageUpdatesCallback;
            hr = XStoreDownloadPackageUpdatesAsync(
                updateContext->storeContextHandle,
                (const char**)(&packageIdentifiers[0]),
                count,
                downloadAsyncBlock.get());

            if (FAILED(hr))
            {
                delete updateContext;
                delete[] packageIdentifiers;
                printf("Failed start download: 0x%x\r\n", hr);
                return;
            }
        }
        else
        {
            downloadAsyncBlock->callback = DownloadAndInstallPackageUpdatesCallback;
            hr = XStoreDownloadAndInstallPackageUpdatesAsync(
                updateContext->storeContextHandle,
                (const char**)(&packageIdentifiers[0]),
                count,
                downloadAsyncBlock.get());

            if (FAILED(hr))
            {
                delete updateContext;
                delete[] packageIdentifiers;
                printf("Failed start download and install: 0x%x\r\n", hr);
                return;
            }
        }

        delete[] packageIdentifiers;
    }
    else
    {
        delete updateContext;
    }
}

void QueryGameAndDlcPackageUpdates(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, bool downloadOnly)
{
    UpdateContext* updateContext = new UpdateContext;
    updateContext->storeContextHandle = storeContextHandle;
    updateContext->taskQueueHandle = taskQueueHandle;
    updateContext->downloadOnly = downloadOnly;

    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->context = updateContext;
    asyncBlock->callback = QueryGameAndDlcPackageUpdatesCallback;

    HRESULT hr = XStoreQueryGameAndDlcPackageUpdatesAsync(
        storeContextHandle,
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to query game and DLC updates: 0x%x\r\n", hr);
        delete updateContext;
        return;
    }
    
    if(FAILED(XAsyncGetStatus(asyncBlock, true))) 
    { 
        printf("XStoreQueryGameAndDlcPackageUpdatesAsync failed\r\n"); 
        return; 
    } 
}

```

## Configuration requise

**En-tête :** XStore.h (inclus dans XGameRuntime.h)

**Bibliothèque :** xgameruntime.lib

**Plateformes prises en charge :** Windows, consoles de la famille XBOX One et consoles XBOX Series

## Documentation conceptuelle

* [Vérification des mises à jour](/fr-CA/publishing/xstore-commerce/xstore-checking-updates)

## Voir aussi

[XStore](/fr-CA/reference/system/xstore/xstore_members)\
[XStoreQueryGameAndDlcPackageUpdatesResult](/fr-CA/reference/system/xstore/functions/xstorequerygameanddlcpackageupdatesresult)\
[XStoreQueryGameAndDlcPackageUpdatesResultCount](/fr-CA/reference/system/xstore/functions/xstorequerygameanddlcpackageupdatesresultcount)\
[Hubs de jeux de franchise](https://learn.microsoft.com/gaming/gdk/docs/store/franchise-game-hubs)


## Related topics

- [XStoreQueryGameAndDlcPackageUpdatesAsync](/reference/system/xstore/functions/xstorequerygameanddlcpackageupdatesasync.md)
- [XStoreQueryGameAndDlcPackageUpdatesResult](/reference/system/xstore/functions/xstorequerygameanddlcpackageupdatesresult.md)
- [XStoreQueryGameAndDlcPackageUpdatesResultCount](/reference/system/xstore/functions/xstorequerygameanddlcpackageupdatesresultcount.md)
