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

# XStoreCanAcquireLicenseForPackageAsync

> XStoreCanAcquireLicenseForPackageAsync

# XStoreCanAcquireLicenseForPackageAsync

检索 DLC（附带包的 Durable）的预览许可证。
此 API 允许游戏查看 Durable 的包是否可获取许可证，但不会实际获取许可证。

## 语法

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

### 参数

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

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

*packageIdentifier*   \_In\_z\_\
类型：char\*

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

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

## 备注

要检索预览许可证以及此函数的执行结果，请在调用此函数之后调用 [XStoreCanAcquireLicenseForPackageResult](/reference/system/xstore/functions/xstorecanacquirelicenseforpackageresult)。
此函数需要联网连接，并且仅检查是否可以获取某个包的许可证。
若要获取某个包的许可证，请调用 [XStoreAcquireLicenseForPackageAsync](/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync)。

以下代码片段演示了如何使用以下 API：

* [XStoreCanAcquireLicenseForPackageAsync](/reference/system/xstore/functions/xstorecanacquirelicenseforpackageasync)
* [XStoreCanAcquireLicenseForPackageResult](/reference/system/xstore/functions/xstorecanacquirelicenseforpackageresult)

```cpp theme={null}
void CALLBACK CanAcquireLicenseForPackageCallback(XAsyncBlock* asyncBlock)
{
    XStoreCanAcquireLicenseResult canAcquireLicenseResult{};

    HRESULT hr = XStoreCanAcquireLicenseForPackageResult(
        asyncBlock,
        &canAcquireLicenseResult);

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

    printf("status       : %d\r\n", canAcquireLicenseResult.status);
    printf("licensableSku: %s\r\n", canAcquireLicenseResult.licensableSku);
}

void CanAcquireLicenseForPackage(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char* packageIdentifier)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->callback = CanAcquireLicenseForPackageCallback;

    HRESULT hr = XStoreCanAcquireLicenseForPackageAsync(
        storeContextHandle,
        packageIdentifier,
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to get preview license for package: 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-granting-access-to-content)
* [管理和授权可下载内容 (DLC)](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-manage-and-license-optional-packages)
* [启用许可证测试](/publishing/xstore-commerce/xstore-licensing-setup)

## 另请参阅

[XStore](/reference/system/xstore/xstore_members)\
[XStoreCanAcquireLicenseForPackageResult](/reference/system/xstore/functions/xstorecanacquirelicenseforpackageresult)\
[XStoreAcquireLicenseForPackageAsync](/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync)\
[管理和授权可下载内容 (DLC)](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-manage-and-license-optional-packages)


## Related topics

- [XStoreCanAcquireLicenseForPackageResult](/zh-CN/reference/system/xstore/functions/xstorecanacquirelicenseforpackageresult.md)
- [XStoreAcquireLicenseForPackageAsync](/zh-CN/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync.md)
- [XStoreCanAcquireLicenseResult](/zh-CN/reference/system/xstore/structs/xstorecanacquirelicenseresult.md)
- [XStoreCanLicenseStatus](/zh-CN/reference/system/xstore/enums/xstorecanlicensestatus.md)
- [启用授权测试](/zh-CN/publishing/xstore-commerce/xstore-licensing-setup.md)
