Compartir a través de


XStoreQueryPackageUpdatesAsync

Retrieves a list of available updates for the packages specified in the argument that can then be used to download and install these updates.

Syntax

HRESULT XStoreQueryPackageUpdatesAsync (   
         const XStoreContextHandle storeContextHandle,    
         const char** packageIdentifiers,   
         size_t packageIdentifiersCount,   
         XAsyncBlock* async   

)   

Parameters

storeContextHandle   _In_
Type: XStoreContextHandle

The store context handle for the user returned by XStoreCreateContext.

packageIdentifiers   _In_z_count_(packageIdentifiersCount)
Type: char**

List of package identifier strings. A package identifier uniquely identifies a package from the Microsoft Store. For more information about package identifiers, see Manage and license downloadable content (DLC).

packageIdentifiersCount   _In_
Type: size_t

The number of Identifiers in packageIdentifiers.

async   _Inout_
Type: XAsyncBlock*

An XAsyncBlock defining the asynchronous work being done. The XAsyncBlock can be used to poll for the call's status and retrieve call results. See XAsyncBlock for more information.

Return value

Type: HRESULT

HRESULT success or error code.

Remarks

To retrieve the list of available updates as well as the execution result of this function call XStoreQueryPackageUpdatesResult after calling this function. To get the number of updates to retrieve call XStoreQueryPackageUpdatesResultCount after calling this function. The result count function is important as it will allow you to determine the appropriate size of array to pass to the result function.

The following code snippet shows an example of retrieving game and optional updates for the packages specified.

void CALLBACK QueryPackageUpdatesCallback(XAsyncBlock* asyncBlock)
{
    uint32_t count;

    HRESULT hr = XStoreQueryPackageUpdatesResultCount(
        asyncBlock,
        &count);

    if (FAILED(hr))
    {
        printf("XStoreQueryPackageUpdatesResultCount failed : 0x%x\n", hr);
        return;
    }

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

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

        if (FAILED(hr))
        {
            delete[] updates;
            printf("XStoreQueryPackageUpdatesResult failed: 0x%x\n", hr);
            return;
        }

        for (uint32_t index = 0; index < count; index++)
        {
            printf("Update found for packageIdentifier: %s\n", updates[index].packageIdentifier);

            // Proceed to XStoreDownloadAndInstallPackageUpdates flow
        }

        delete[] updates;
    }
}

void QueryPackageUpdates(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle)
{
    std::vector<std::string> packageIds;

    HRESULT hr = XPackageEnumeratePackages(
        XPackageKind::Game,
        XPackageEnumerationScope::ThisAndRelated,
        &packageIds, [](void* context, const XPackageDetails* details) -> bool
        {
            auto packageIds = reinterpret_cast<std::vector<std::string>*>(context);

            printf("Identifier: %s name: %s\n", details->packageIdentifier, details->displayName);
            packageIds->push_back(details->packageIdentifier);
        });

    // packageIds now populated with ids for all installed packages

    auto asyncBlock = new XAsyncBlock();
    asyncBlock->queue = m_asyncQueue;
    asyncBlock->callback = QueryPackageUpdatesCallback;

    hr = XStoreQueryPackageUpdatesAsync(
        m_storeContext,
        packageIds.data(),
        packageIds.size(),
        asyncBlock);

    if (FAILED(hr))
    {
        printf("XStoreQueryPackageUpdatesAsync failed: 0x%x\n", hr);
        return;
    }
}   

Requirements

Header: XStore.h (included in XGameRuntime.h)

Library: xgameruntime.lib

Supported platforms: Windows, Xbox One family consoles and Xbox Series consoles

See also

XStore
XStoreQueryPackageUpdatesResult
XStoreQueryPackageUpdatesResultCount