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

列舉附加至數位遊戲授權之任何耐久性附加元件的授權。
這僅適用於不含套件類型的耐久性項目，而且只能搭配數位授權使用，不能搭配光碟授權使用。
使用光碟授權執行此函式會得到空白結果，即使存在使用者所擁有或可授權的個別耐久性項目也是如此。
針對光碟案例，請改用 [XStoreAcquireLicenseForDurablesAsync](/zh-TW/reference/system/xstore/functions/xstoreacquirelicensefordurablesasync)。

## 語法

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

### 參數

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

[XStoreCreateContext](/zh-TW/reference/system/xstore/functions/xstorecreatecontext) 所傳回之使用者的市集內容控制代碼。

*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 成功或錯誤碼。

## 備註

若要擷取附加元件授權以及此函式的執行結果，請在呼叫此函式之後呼叫 [XStoreQueryAddonLicensesResult](/zh-TW/reference/system/xstore/functions/xstorequeryaddonlicensesresult)。
若要擷取此函式取得的授權數目，請在呼叫此函式之後呼叫 [XStoreQueryAddonLicensesResultCount](/zh-TW/reference/system/xstore/functions/xstorequeryaddonlicensesresultcount)。
結果計數函式很重要，因為它可讓您判斷要傳遞給結果函式的適當陣列大小。

下列程式碼片段示範如何擷取使用者擁有或可授權的耐久性附加元件授權 (不含套件)：

```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 主機

## 概念文件

* [基本市集作業](/zh-TW/publishing/xstore-commerce/xstore-basic-operations)
* [啟用授權測試](/zh-TW/publishing/xstore-commerce/xstore-licensing-setup)

## 另請參閱

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


## Related topics

- [XStoreQueryAddOnLicensesAsync](/reference/system/xstore/functions/xstorequeryaddonlicensesasync.md)
- [XStoreQueryAddOnLicensesResult](/reference/system/xstore/functions/xstorequeryaddonlicensesresult.md)
- [Basic store operations](/publishing/xstore-commerce/xstore-basic-operations.md)
- [Enabling licensing testing](/publishing/xstore-commerce/xstore-licensing-setup.md)
- [라이선싱 테스트 활성화](/ko/publishing/xstore-commerce/xstore-licensing-setup.md)
