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

# XStoreQueryGameLicenseAsync

> XStoreQueryGameLicenseAsync

# XStoreQueryGameLicenseAsync

擷取為允許應用程式啟動而取得之授權的相關資訊。

## 語法

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

### 參數

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

由 [XStoreCreateContext](https://docs.xbox.com/zh-TW/reference/system/xstore/functions/xstorecreatecontext.md) 傳回之使用者的商店內容控制代碼。

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

定義正在進行之非同步工作的 [XAsyncBlock](https://docs.xbox.com/zh-TW/reference/system/xasync/structs/xasyncblock.md)。[XAsyncBlock](https://docs.xbox.com/zh-TW/reference/system/xasync/structs/xasyncblock.md) 可用來輪詢呼叫的狀態並擷取呼叫結果。如需詳細資訊，請參閱 [XAsyncBlock](https://docs.xbox.com/zh-TW/reference/system/xasync/structs/xasyncblock.md)。

### 傳回值

類型：HRESULT

HRESULT 成功或錯誤碼。

## 備註

若要擷取授權資訊以及此函式的執行結果，請在呼叫此函式之後呼叫 [XStoreQueryGameLicenseResult](https://docs.xbox.com/zh-TW/reference/system/xstore/functions/xstorequerygamelicenseresult.md)。[XStoreQueryGameLicenseResult](https://docs.xbox.com/zh-TW/reference/system/xstore/functions/xstorequerygamelicenseresult.md) 應在 **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 遊戲的模組支援](https://docs.xbox.com/zh-TW/build/core-features/common/packaging/packaging-mods.md)
* [啟用授權測試](https://docs.xbox.com/zh-TW/publishing/xstore-commerce/xstore-licensing-setup.md)
* [GDK 商務系統概觀](https://docs.xbox.com/zh-TW/publishing/xstore-commerce/xstore-overview.md)
* [啟用 XStore 開發與測試](https://docs.xbox.com/zh-TW/publishing/xstore-commerce/xstore-product-testing-setup.md)

## 另請參閱

[XStore](https://docs.xbox.com/zh-TW/reference/system/xstore/xstore_members.md)\
[XStoreQueryGameLicenseResult](https://docs.xbox.com/zh-TW/reference/system/xstore/functions/xstorequerygamelicenseresult.md)\
[XStoreCreateContext](https://docs.xbox.com/zh-TW/reference/system/xstore/functions/xstorecreatecontext.md)


## Related topics

- [XStoreQueryGameLicenseResult](https://docs.xbox.com/zh-TW/reference/system/xstore/functions/xstorequerygamelicenseresult.md)
- [XStoreGameLicense](https://docs.xbox.com/zh-TW/reference/system/xstore/structs/xstoregamelicense.md)
- [啟用授權測試](https://docs.xbox.com/zh-TW/publishing/xstore-commerce/xstore-licensing-setup.md)
- [PC 上的 XStore — DRM、授權權杖和沙箱](https://docs.xbox.com/zh-TW/publishing/xstore-commerce/xstore-pc.md)
- [GDK 商務系統概觀](https://docs.xbox.com/zh-TW/publishing/xstore-commerce/xstore-overview.md)
