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

# XStoreQueryGameLicenseAsync

> XStoreQueryGameLicenseAsync

# XStoreQueryGameLicenseAsync

检索允许应用启动的许可证的信息。

## 语法

```cpp theme={null}
HRESULT XStoreQueryGameLicenseAsync(  
         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 成功或错误代码。

## 备注

要检索许可证信息以及此函数的执行结果，请在调用此函数后调用 [XStoreQueryGameLicenseResult](/reference/system/xstore/functions/xstorequerygamelicenseresult)。[XStoreQueryGameLicenseResult](/reference/system/xstore/functions/xstorequerygamelicenseresult) 应在 **XStoreQueryGameLicenseAsync** 的回调函数中调用。以下代码片段演示了检索允许游戏启动的许可证信息的示例。

```cpp theme={null}
void CALLBACK GameLicenseCallback(XAsyncBlock* asyncBlock)
{
    XStoreGameLicense result{};

    HRESULT hr = XStoreQueryGameLicenseResult(
        asyncBlock,
        &result);

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

    printf("expirationDate        : %d\r\n", result.expirationDate);
    printf("isActive              : %s\r\n", result.isActive ? "true" : "false");
    printf("isDiscLicense         : %s\r\n", result.isDiscLicense ? "true" : "false");
    printf("isTrial               : %s\r\n", result.isTrial ? "true" : "false");
    printf("isTrialOwnedByThisUser: %s\r\n", result.isTrialOwnedByThisUser ? "true" : "false");
    printf("skuStoreId            : %s\r\n", result.skuStoreId);
    printf("trialTimeRemaining    : %d\r\n", result.trialTimeRemainingInSeconds);
    printf("trialUniqueId         : %s\r\n", result.trialUniqueId);
}

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

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

    if (FAILED(hr))
    {
        printf("Failed to get the game license: 0x%x\r\n", hr);
        return;
    }
}
```

## 要求

**头文件：** XStore.h（包含于 XGameRuntime.h 中）

**库：** xgameruntime.lib

**支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## 概念文档

* [PC GDK 游戏的 Mods 支持](/build/core-features/common/packaging/packaging-mods)
* [启用许可证测试](/publishing/xstore-commerce/xstore-licensing-setup)
* [GDK 商务系统概述](/publishing/xstore-commerce/xstore-overview)
* [启用 XStore 开发和测试](/publishing/xstore-commerce/xstore-product-testing-setup)

## 另请参阅

[XStore](/reference/system/xstore/xstore_members)\
[XStoreQueryGameLicenseResult](/reference/system/xstore/functions/xstorequerygamelicenseresult)\
[XStoreCreateContext](/reference/system/xstore/functions/xstorecreatecontext)


## Related topics

- [XStoreQueryGameLicenseResult](/zh-CN/reference/system/xstore/functions/xstorequerygamelicenseresult.md)
- [XStoreGameLicense](/zh-CN/reference/system/xstore/structs/xstoregamelicense.md)
- [启用授权测试](/zh-CN/publishing/xstore-commerce/xstore-licensing-setup.md)
- [PC 上的 XStore — DRM、许可证令牌和沙盒](/zh-CN/publishing/xstore-commerce/xstore-pc.md)
- [GDK 商务系统概述](/zh-CN/publishing/xstore-commerce/xstore-overview.md)
