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

取得指定產品識別碼的消耗性剩餘餘額。

## 語法

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

### 參數

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

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

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

要擷取其餘額之消耗性產品的識別碼。

*async*   \_Inout\_\
類型：[XAsyncBlock\*](/zh-TW/reference/system/xasync/structs/xasyncblock)

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

### 傳回值

類型：HRESULT

HRESULT 成功或錯誤碼。

## 備註

若要擷取剩餘的消耗性餘額以及此函式的執行結果，請在呼叫此函式之後呼叫 [XStoreQueryConsumableBalanceRemainingResult](/zh-TW/reference/system/xstore/functions/xstorequeryconsumablebalanceremainingresult)。[XStoreQueryConsumableBalanceRemainingResult](/zh-TW/reference/system/xstore/functions/xstorequeryconsumablebalanceremainingresult) 應在 **XStoreQueryConsumableBalanceRemainingAsync** 的回呼函式中執行。下列程式碼片段示範如何擷取指定產品識別碼的消耗性剩餘餘額。

```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 主機

## 概念文件

* [基本商店作業](/zh-TW/publishing/xstore-commerce/xstore-basic-operations)

## 另請參閱

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


## Related topics

- [XStoreQueryConsumableBalanceRemainingAsync](/reference/system/xstore/functions/xstorequeryconsumablebalanceremainingasync.md)
- [XStoreQueryConsumableBalanceRemainingResult](/reference/system/xstore/functions/xstorequeryconsumablebalanceremainingresult.md)
