> ## 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](/zh-TW/reference/system/xstore/functions/xstorecreatecontext) 傳回的使用者市集內容控制代碼。

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

套件識別碼字串的清單。
套件識別碼可唯一識別來自 Microsoft Store 的套件。如需套件識別碼的詳細資訊，請參閱[管理可下載內容 (DLC) 並授權](/zh-TW/publishing/xstore-commerce/xstore-dlc)。

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

`packageIdentifiers` 中的識別碼數目。

*async*   \_Inout\_\
類型：[XAsyncBlock\*](/zh-TW/reference/system/xasync/structs/xasyncblock)

定義非同步工作的 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock)。使用 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock) 輪詢呼叫的狀態並擷取呼叫結果。如需詳細資訊，請參閱 [XAsyncBlock](/zh-TW/reference/system/xasync/structs/xasyncblock)。

### 傳回值

類型：HRESULT

HRESULT 成功或錯誤碼。

## 備註

若要取得目前執行中遊戲的套件識別碼，請使用 [XPackageGetCurrentProcessPackageIdentifier](/zh-TW/reference/system/xpackage/functions/xpackagegetcurrentprocesspackageidentifier)，或使用 [XPackageEnumeratePackages](/zh-TW/reference/system/xpackage/functions/xpackageenumeratepackages) 取得 DLC 和相關遊戲的套件識別碼。

若要擷取可用更新的清單以及此函式的執行結果，請在呼叫此函式之後呼叫 [XStoreQueryPackageUpdatesResult](/zh-TW/reference/system/xstore/functions/xstorequerypackageupdatesresult)。若要取得要擷取的更新數目，請在呼叫此函式之後呼叫 [XStoreQueryPackageUpdatesResultCount](/zh-TW/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 主機

## 概念文件

* [檢查更新](/zh-TW/publishing/xstore-commerce/xstore-checking-updates)

## 另請參閱

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


## Related topics

- [XStoreQueryPackageUpdatesAsync](/reference/system/xstore/functions/xstorequerypackageupdatesasync.md)
- [XStoreQueryPackageUpdatesResult](/reference/system/xstore/functions/xstorequerypackageupdatesresult.md)
- [XStoreQueryPackageUpdatesResultCount](/reference/system/xstore/functions/xstorequerypackageupdatesresultcount.md)
