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

# XStoreDownloadAndInstallPackagesAsync

> XStoreDownloadAndInstallPackagesAsync

# XStoreDownloadAndInstallPackagesAsync

指定されたストア パッケージをダウンロードしてインストールします。

## 構文

```cpp theme={null}
HRESULT XStoreDownloadAndInstallPackagesAsync(  
         const XStoreContextHandle storeContextHandle,  
         const char** storeIds,  
         size_t storeIdsCount,  
         XAsyncBlock* async  
)  
```

### パラメーター

*storeContextHandle*   \_In\_\
Type: XStoreContextHandle

[XStoreCreateContext](/reference/system/xstore/functions/xstorecreatecontext) から返される、ユーザーのストア コンテキスト ハンドル。

*storeIds*   \_In\_z\_count\_(storeIdsCount)\
Type: char\*\*

パッケージ識別子文字列のリスト。
パッケージ識別子は、Microsoft Store からのパッケージを一意に識別します。パッケージ識別子の詳細については、[ダウンロード可能なコンテンツ (DLC) の管理とライセンス](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-manage-and-license-optional-packages)を参照してください。

*storeIdsCount*   \_In\_\
Type: size\_t

**storeIds** 内の ID の数。

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

実行中の非同期処理を定義する [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)。[XAsyncBlock](/reference/system/xasync/structs/xasyncblock) は、呼び出しの状態のポーリングと呼び出し結果の取得に使用できます。詳細については、[XAsyncBlock](/reference/system/xasync/structs/xasyncblock) を参照してください。

### 戻り値

Type: [HRESULT](https://learn.microsoft.com/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a)

HRESULT の成功またはエラー コード。

## 解説

この関数のダウンロードおよびインストール結果を取得するには、この関数を呼び出した後に [XStoreDownloadAndInstallPackagesResult](/reference/system/xstore/functions/xstoredownloadandinstallpackagesresult) を呼び出します。ダウンロードおよびインストールされた項目の数を取得するには、この関数を呼び出した後に [XStoreDownloadAndInstallPackagesResultCount](/reference/system/xstore/functions/xstoredownloadandinstallpackagesresultcount) を呼び出します。結果カウント関数は、結果関数に渡す適切な配列サイズを決定できるようにするため重要です。

この API が実行中のゲームから呼び出されると、ダウンロードは高優先度と見なされ、この API の storeIds パラメーターで指定された順序でキューの先頭に配置されます。

次のコード スニペットは、ストア パッケージをダウンロードしてインストールする例を示しています。

```cpp theme={null}
  
void CALLBACK DownloadAndInstallPackagesCallback(XAsyncBlock* asyncBlock)
{
    uint32_t count;

    HRESULT hr = XStoreDownloadAndInstallPackagesResultCount(
        asyncBlock,
        &count);

    if (FAILED(hr))
    {
        printf("Failed retrieve the installing packages count: 0x%x\r\n", hr);
        return;
    }

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

    auto packageIdentifiers = new char[count][XPACKAGE_IDENTIFIER_MAX_LENGTH];
    hr = XStoreDownloadAndInstallPackagesResult(
        asyncBlock,
        count,
        &packageIdentifiers[0]);

    if (FAILED(hr))
    {
        delete[] packageIdentifiers;
        printf("Failed retrieve the installing packages results: 0x%x\r\n", hr);
        return;
    }

    for (uint32_t index = 0; index < count; index++)
    {
        printf("packageIdentifier: %s\r\n", packageIdentifiers[index]);
    }

    delete[] packageIdentifiers;
}

void DownloadAndInstallPackages(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char** storeIds, size_t storeIdsCount)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->callback = DownloadAndInstallPackagesCallback;

    HRESULT hr = XStoreDownloadAndInstallPackagesAsync(
        storeContextHandle,
        storeIds,
        storeIdsCount,
        asyncBlock.get());

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

## 要件

**ヘッダー:** XStore.h (XGameRuntime.h に含まれる)

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One 本体および XBOX Series 本体

## 関連概念ドキュメント

* [ダウンロード可能なコンテンツ (DLC) の管理とライセンス](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-manage-and-license-optional-packages)

## 関連項目

[XStore](/reference/system/xstore/xstore_members)\
[XStoreDownloadAndInstallPackagesResult](/reference/system/xstore/functions/xstoredownloadandinstallpackagesresult)\
[XStoreDownloadAndInstallPackagesResultCount](/reference/system/xstore/functions/xstoredownloadandinstallpackagesresultcount)


## Related topics

- [XStoreDownloadAndInstallPackagesResult](/ja-jp/reference/system/xstore/functions/xstoredownloadandinstallpackagesresult.md)
- [XStoreDownloadAndInstallPackagesResultCount](/ja-jp/reference/system/xstore/functions/xstoredownloadandinstallpackagesresultcount.md)
- [XStoreQueryPackageIdentifier](/ja-jp/reference/system/xstore/functions/xstorequerypackageidentifier.md)
- [ダウンロード可能なコンテンツ (DLC) の管理とライセンス供与](/ja-jp/publishing/xstore-commerce/xstore-dlc.md)
- [XStoreShowProductPageUIResult](/ja-jp/reference/system/xstore/functions/xstoreshowproductpageuiresult.md)
