XStoreQueryConsumableBalanceRemainingAsync

Get the consumable balance remaining for the specified product ID.

Syntax

HRESULT XStoreQueryConsumableBalanceRemainingAsync(  
         const XStoreContextHandle storeContextHandle,  
         const char* storeProductId,  
         XAsyncBlock* async  
)  

Parameters

storeContextHandle   _In_
Type: XStoreContextHandle

The store context handle for the user returned by XStoreCreateContext.

storeProductId   _In_z_
Type: char*

The ID of the consumable to retrieve the balance for.

async   _Inout_
Type: XAsyncBlock*

An XAsyncBlock defining the asynchronous work being done. The XAsyncBlock can be used to poll for the call's status and retrieve call results. See XAsyncBlock for more information.

Return value

Type: HRESULT

HRESULT success or error code.

Remarks

To retrieve the remaining consumable balance as well as the execution result of this function call XStoreQueryConsumableBalanceRemainingResult after calling this function. XStoreQueryConsumableBalanceRemainingResult should be executed in the callback function for XStoreQueryConsumableBalanceRemainingAsync. The following code snippet shows an example of retrieving the consumable balance remaining for a specified product ID.

void CALLBACK QueryConsumableBalanceRemainingCallback(XAsyncBlock* asyncBlock)
{
    XStoreConsumableResult result{};
    HRESULT hr = XStoreQueryConsumableBalanceRemainingResult(
        asyncBlock,
        &result);

    if (FAILED(hr))
    {
        printf("Failed retrieve the consumable balance remaining: 0x%x\r\n", hr);
        return;
    }

    printf("quantity: %d\r\n", result.quantity);
}

void QueryConsumableBalanceRemaining(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char* storeId)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->context = taskQueueHandle;
    asyncBlock->callback = QueryConsumableBalanceRemainingCallback;

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

    if (FAILED(hr))
    {
        printf("Failed to get consumable balance remaining: 0x%x\r\n", hr);
        return;
    }

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

Requirements

Header: XStore.h (included in XGameRuntime.h)

Library: xgameruntime.lib

Supported platforms: Windows, Xbox One family consoles and Xbox Series consoles

See also

XStore
XStoreQueryConsumableBalanceRemainingResult
XStoreCreateContext