> ## Documentation Index
> Fetch the complete documentation index at: https://docs.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](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorecreatecontext.md) 返回的用户的应用商店上下文句柄。

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

唯一标识应用商店包的字符串。有关包标识符的详细信息，请参阅[管理和授权可下载内容 (DLC)](https://docs.xbox.com/zh-CN/publishing/xstore-commerce/xstore-dlc.md)。

*async*   \_Inout\_\
类型：[XAsyncBlock\*](https://docs.xbox.com/zh-CN/reference/system/xasync/structs/xasyncblock.md)

定义正在执行的异步工作的 [XAsyncBlock](https://docs.xbox.com/zh-CN/reference/system/xasync/structs/xasyncblock.md)。
可使用 [XAsyncBlock](https://docs.xbox.com/zh-CN/reference/system/xasync/structs/xasyncblock.md) 轮询调用状态并检索调用结果。
有关详细信息，请参阅 [XAsyncBlock](https://docs.xbox.com/zh-CN/reference/system/xasync/structs/xasyncblock.md)。

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

## 备注

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

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

* [XStoreCanAcquireLicenseForPackageAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorecanacquirelicenseforpackageasync.md)
* [XStoreCanAcquireLicenseForPackageResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorecanacquirelicenseforpackageresult.md)

```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://docs.xbox.com/zh-CN/publishing/xstore-commerce/xstore-granting-access.md)
* [管理和授权可下载内容 (DLC)](https://docs.xbox.com/zh-CN/publishing/xstore-commerce/xstore-dlc.md)
* [启用许可证测试](https://docs.xbox.com/zh-CN/publishing/xstore-commerce/xstore-licensing-setup.md)

## 另请参阅

[XStore](https://docs.xbox.com/zh-CN/reference/system/xstore/xstore_members.md)\
[XStoreCanAcquireLicenseForPackageResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorecanacquirelicenseforpackageresult.md)\
[XStoreAcquireLicenseForPackageAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync.md)\
[管理和授权可下载内容 (DLC)](https://docs.xbox.com/zh-CN/publishing/xstore-commerce/xstore-dlc.md)


## Related topics

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