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

# XStoreQueryConsumableBalanceRemainingAsync

> XStoreQueryConsumableBalanceRemainingAsync

# XStoreQueryConsumableBalanceRemainingAsync

获取指定产品 ID 的剩余可消耗余额。

## 语法

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

### 参数

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

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

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

要检索余额的可消耗品的 ID。

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

## 备注

要检索剩余的可消耗品余额以及此函数的执行结果，请在调用此函数后调用 [XStoreQueryConsumableBalanceRemainingResult](/reference/system/xstore/functions/xstorequeryconsumablebalanceremainingresult)。[XStoreQueryConsumableBalanceRemainingResult](/reference/system/xstore/functions/xstorequeryconsumablebalanceremainingresult) 应在 **XStoreQueryConsumableBalanceRemainingAsync** 的回调函数中执行。以下代码片段演示了检索指定产品 ID 的剩余可消耗余额的示例。

```cpp theme={null}
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->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;
    }
}

```

## 要求

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

**库：** xgameruntime.lib

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

## 概念文档

* [基本应用商店操作](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-basic-store-operations)

## 另请参阅

[XStore](/reference/system/xstore/xstore_members)\
[XStoreQueryConsumableBalanceRemainingResult](/reference/system/xstore/functions/xstorequeryconsumablebalanceremainingresult)\
[XStoreCreateContext](/reference/system/xstore/functions/xstorecreatecontext)


## Related topics

- [XStoreQueryConsumableBalanceRemainingResult](/zh-CN/reference/system/xstore/functions/xstorequeryconsumablebalanceremainingresult.md)
- [XStoreConsumableResult](/zh-CN/reference/system/xstore/structs/xstoreconsumableresult.md)
- [商店基本操作](/zh-CN/publishing/xstore-commerce/xstore-basic-operations.md)
- [XStore](/zh-CN/reference/system/xstore/xstore_members.md)
- [面向 GDK 的 Unity C# API 包装器](/zh-CN/build/gdk-and-engines/unity/unity-api-wrappers.md)
