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

# XStoreQueryPackageUpdatesAsync

> XStoreQueryPackageUpdatesAsync

# XStoreQueryPackageUpdatesAsync

检索参数中指定的包的可用更新列表。使用此列表下载和安装更新。

## 语法

```cpp theme={null}
HRESULT XStoreQueryPackageUpdatesAsync (   
         const XStoreContextHandle storeContextHandle,    
         const char** packageIdentifiers,   
         size_t packageIdentifiersCount,   
         XAsyncBlock* async   

)   
```

### 参数

*storeContextHandle*   \_In\_\
类型：XStoreContextHandle

由 [XStoreCreateContext](/reference/system/xstore/functions/xstorecreatecontext) 返回的用户的应用商店上下文句柄。

*packageIdentifiers*   \_In\_z\_count\_(packageIdentifiersCount)\
类型：char\*\*

包标识符字符串的列表。
包标识符唯一标识来自 Microsoft Store 的包。有关包标识符的详细信息，请参阅[管理和授权可下载内容 (DLC)](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-manage-and-license-optional-packages)。

*packageIdentifiersCount*   \_In\_\
类型：size\_t

`packageIdentifiers` 中的标识符数量。

*async*   \_Inout\_\
类型：[XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

定义异步工作的 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。使用 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) 轮询调用状态并检索调用结果。有关详细信息，请参阅 [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

## 备注

要获取当前正在运行的游戏的包标识符，请使用 [XPackageGetCurrentProcessPackageIdentifier](/reference/system/xpackage/functions/xpackagegetcurrentprocesspackageidentifier)，或使用 [XPackageEnumeratePackages](/reference/system/xpackage/functions/xpackageenumeratepackages) 获取 DLC 和相关游戏的包标识符。

要检索可用更新列表以及此函数的执行结果，请在调用此函数后调用 [XStoreQueryPackageUpdatesResult](/reference/system/xstore/functions/xstorequerypackageupdatesresult)。要获取要检索的更新数量，请在调用此函数后调用 [XStoreQueryPackageUpdatesResultCount](/reference/system/xstore/functions/xstorequerypackageupdatesresultcount)。结果计数函数很重要，因为它可以让你确定要传递给结果函数的合适数组大小。

以下代码片段演示了检索指定包的游戏和可选更新的示例。

```cpp theme={null}
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;
    }
}   

```

## 要求

**头文件：** XStore.h（包含于 XGameRuntime.h 中）

**库：** xgameruntime.lib

**支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## 概念文档

* [检查更新](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-checking-for-updates)

## 另请参阅

[XStore](/reference/system/xstore/xstore_members)\
[XStoreQueryPackageUpdatesResult](/reference/system/xstore/functions/xstorequerypackageupdatesresult)\
[XStoreQueryPackageUpdatesResultCount](/reference/system/xstore/functions/xstorequerygameanddlcpackageupdatesresultcount)


## Related topics

- [XStoreQueryPackageUpdatesResult](/zh-CN/reference/system/xstore/functions/xstorequerypackageupdatesresult.md)
- [XStoreQueryPackageUpdatesResultCount](/zh-CN/reference/system/xstore/functions/xstorequerypackageupdatesresultcount.md)
- [检查更新](/zh-CN/publishing/xstore-commerce/xstore-checking-updates.md)
- [XStore](/zh-CN/reference/system/xstore/xstore_members.md)
- [XStoreQueryGameAndDlcPackageUpdatesAsync](/zh-CN/reference/system/xstore/functions/xstorequerygameanddlcpackageupdatesasync.md)
