XStoreQueryGameLicenseAsync

检索有关获取来允许启动应用程序的许可证的信息。

语法

HRESULT XStoreQueryGameLicenseAsync(  
         const XStoreContextHandle storeContextHandle,  
         XAsyncBlock* async  
)  

参数

storeContextHandle _In_
类型:XStoreContextHandle

XStoreCreateContext 返回的用户的应用商店上下文句柄。

async _Inout_
类型:XAsyncBlock*

用于定义正在进行的异步工作的 XAsyncBlockXAsyncBlock 可用于轮询调用的状态和检索调用结果。 有关详细信息,请参阅 XAsyncBlock

返回值

类型:HRESULT

HRESULT 成功或错误代码。

备注

要检索许可证信息以及此函数的执行结果,请在调用此函数后调用 XStoreQueryGameLicenseResultXStoreQueryGameLicenseResult 应该在 XStoreQueryGameLicenseAsync 的回调函数中调用。 以下代码段显示一个示例,用于检索获取来允许启动游戏的许可证的信息。

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;
    }

    // Wait a while for the callbacks to run
    Sleep(1000);
}

要求

头文件:XStore.h(包含在 XGameRuntime.h 中)

库:xgameruntime.lib

支持平台:Windows、Xbox One 系列主机和 Xbox Series 主机

另请参阅

XStore
XStoreQueryGameLicenseResult
XStoreCreateContext