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

# XStoreQueryAddOnLicensesAsync

> XStoreQueryAddOnLicensesAsync

# XStoreQueryAddOnLicensesAsync

枚举附加到数字游戏许可证的任何 Durable 附加内容的许可证。
这仅适用于不带包类型的 Durable，并且只能用于数字许可证，不能用于光盘许可证。
使用光盘许可证运行此函数将返回空结果，即使用户拥有或可以获取许可证的单个 Durable 存在也是如此。
对于光盘场景，请改用 [XStoreAcquireLicenseForDurablesAsync](/reference/system/xstore/functions/xstoreacquirelicensefordurablesasync)。

## 语法

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

### 参数

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

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

*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 成功或错误代码。

## 备注

要检索附加内容许可证以及此函数的执行结果，请在调用此函数后调用 [XStoreQueryAddonLicensesResult](/reference/system/xstore/functions/xstorequeryaddonlicensesresult)。
要检索通过此函数获取的许可证数量，请在调用此函数后调用 [XStoreQueryAddonLicensesResultCount](/reference/system/xstore/functions/xstorequeryaddonlicensesresultcount)。
结果计数函数很重要，因为它可以让你确定要传递给结果函数的合适数组大小。

以下代码片段演示了检索用户拥有或可获取许可证的 Durable 附加内容许可证（不带包）的示例：

```cpp theme={null}
void CALLBACK QueryAddOnLicensesCallback(XAsyncBlock* asyncBlock)
{
    uint32_t count;
    HRESULT hr = XStoreQueryAddOnLicensesResultCount(
        asyncBlock,
        &count);

    if (FAILED(hr))
    {
        printf("Failed retrieve the add-on license count: 0x%x\r\n", hr);
        return;
    }

    printf("Number of add-on licenses: %d", count);

    XStoreAddonLicense* addOnLicenses = new XStoreAddonLicense[count];
    hr = XStoreQueryAddOnLicensesResult(asyncBlock, count, &addOnLicenses);

    if (FAILED(hr))
    {
        printf("Failed retrieve the add-on licenses: 0x%x\r\n", hr);
        delete[] addOnLicenses;
        return;
    }

    for (uint32_t index = 0; index < count; index++)
    {
        printf("expirationDate : %d\r\n", addOnLicenses[index].expirationDate);
        printf("inAppOfferToken: %s\r\n", addOnLicenses[index].inAppOfferToken);
        printf("isActive       : %s\r\n", addOnLicenses[index].isActive ? "true" : "false");
        printf("skuStoreId     : %s\r\n", addOnLicenses[index].skuStoreId);
    }

    delete[] addOnLicenses;
}

void QueryAddOnLicenses(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->callback = QueryAddOnLicensesCallback;

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

    if (FAILED(hr))
    {
        printf("Failed to get add-on licenses: 0x%x\r\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-basic-store-operations)
* [启用许可证测试](/publishing/xstore-commerce/xstore-licensing-setup)

## 另请参阅

[XStore](/reference/system/xstore/xstore_members)\
[XStoreQueryAddonLicensesResult](/reference/system/xstore/functions/xstorequeryaddonlicensesresult)\
[XStoreQueryAddonLicensesResultCount](/reference/system/xstore/functions/xstorequeryaddonlicensesresultcount)


## Related topics

- [XStoreQueryAddOnLicensesResult](/zh-CN/reference/system/xstore/functions/xstorequeryaddonlicensesresult.md)
- [启用授权测试](/zh-CN/publishing/xstore-commerce/xstore-licensing-setup.md)
- [商店基本操作](/zh-CN/publishing/xstore-commerce/xstore-basic-operations.md)
- [XStore](/zh-CN/reference/system/xstore/xstore_members.md)
- [面向 GDK 的 Unity C# API 包装器](/zh-CN/build/gdk-and-engines/unity/unity-api-wrappers.md)
