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

# XStoreCanAcquireLicenseForStoreIdAsync

> XStoreCanAcquireLicenseForStoreIdAsync

# XStoreCanAcquireLicenseForStoreIdAsync

检索可授予许可证的内容的预览许可证，包括带包或不带包的 Durables，以及当前已插入光盘中的内容。
此 API 允许游戏查看产品是否可获取许可证，但不会实际获取许可证。

## 语法

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

### 参数

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

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

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

要检查的产品的 StoreID

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

## 备注

**XStoreCanAcquireLicenseForStoreIdAsync** 使游戏能够确定用户是否可以为某项特定内容获取许可证，而不必实际获取该许可证并占用该用户的并发许可名额。
此函数不需要用于当前正在运行的游戏，因为该游戏已具有许可证，但可以用于确定用户是否拥有同一发行商的其他游戏或内容。
例如，游戏可以使用此 API 来确定是否奖励拥有该游戏早期版本（数字版或插入的光盘版）的用户，或者向用户追加销售产品。

要检索预览许可证以及此函数的执行结果，请在调用此函数之后调用 [XStoreCanAcquireLicenseForStoreIdResult](/reference/system/xstore/functions/xstorecanacquirelicenseforstoreidresult)。

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

* **XStoreCanAcquireLicenseForStoreIdAsync**
* [XStoreCanAcquireLicenseForStoreIdResult](/reference/system/xstore/functions/xstorecanacquirelicenseforstoreidresult)

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

    HRESULT hr = XStoreCanAcquireLicenseForStoreIdResult(
        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 CanAcquireLicenseForStoreId(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char* storeId)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->callback = CanAcquireLicenseForStoreIdCallback;

    HRESULT hr = XStoreCanAcquireLicenseForStoreIdAsync(
        storeContextHandle,
        storeId,
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to get preview license for store ID: 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)\
[XStoreCanAcquireLicenseForStoreIdResult](/reference/system/xstore/functions/xstorecanacquirelicenseforstoreidresult)\
[如何使用不带包的 Durable](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-dwobs)\
[向玩家授予附加内容的访问权限](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-granting-access-to-content)


## Related topics

- [XStoreCanAcquireLicenseForStoreIdResult](/zh-CN/reference/system/xstore/functions/xstorecanacquirelicenseforstoreidresult.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)
- [XStore](/zh-CN/reference/system/xstore/xstore_members.md)
