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

# XStoreCanAcquireLicenseForStoreIdAsync

> XStoreCanAcquireLicenseForStoreIdAsync

# XStoreCanAcquireLicenseForStoreIdAsync

擷取可授權內容的預覽授權，包括含或不含套件的耐久性產品，以及目前已插入之光碟上的內容。
此 API 可讓遊戲查看產品是否可授權，但不會實際取得授權。

## 語法

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

### 參數

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

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

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

要檢查之產品的 StoreID

*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 成功或錯誤碼。

## 備註

**XStoreCanAcquireLicenseForStoreIdAsync** 讓遊戲能夠判斷使用者是否可以取得特定內容的授權，而不需實際取得該授權並佔用該使用者的並行位置。
此函式不需要用於目前正在執行的遊戲，因為它已經擁有授權，但可以用來判斷使用者是否擁有相同發行者的其他遊戲或內容。
例如，遊戲可以使用此 API 來判斷是否要獎勵擁有該遊戲先前版本 (數位版或已插入的光碟) 的使用者，或向使用者推銷升級產品。

若要擷取預覽授權及此函式的執行結果，請在呼叫此函式之後呼叫 [XStoreCanAcquireLicenseForStoreIdResult](/zh-TW/reference/system/xstore/functions/xstorecanacquirelicenseforstoreidresult)。

此程式碼片段示範如何使用下列 API：

* **XStoreCanAcquireLicenseForStoreIdAsync**
* [XStoreCanAcquireLicenseForStoreIdResult](/zh-TW/reference/system/xstore/functions/xstorecanacquirelicenseforstoreidresult)

```cpp theme={null}
void CALLBACK CanAcquireLicenseForStoreIdCallback(XAsyncBlock* asyncBlock)
{
    XStoreCanAcquireLicenseResult canAcquireLicenseResult{};

    HRESULT hr = XStoreCanAcquireLicenseForStoreIdResult(
        asyncBlock,
        &canAcquireLicenseResult);

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

    printf("status       : %d\r\n", canAcquireLicenseResult.status);
    printf("licensableSku: %s\r\n", canAcquireLicenseResult.licensableSku);
}

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

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

    if (FAILED(hr))
    {
        printf("Failed to get preview license for store ID: 0x%x\r\n", hr);
        return;
    }
}
```

## 需求

**標頭：** XStore.h (包含在 XGameRuntime.h 中)

**程式庫：** xgameruntime.lib

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 概念文件

* [授予玩家附加元件內容的存取權](/zh-TW/publishing/xstore-commerce/xstore-granting-access)
* [管理及授權可下載內容 (DLC)](/zh-TW/publishing/xstore-commerce/xstore-dlc)
* [啟用授權測試](/zh-TW/publishing/xstore-commerce/xstore-licensing-setup)

## 另請參閱

[XStore](/zh-TW/reference/system/xstore/xstore_members)\
[XStoreCanAcquireLicenseForStoreIdResult](/zh-TW/reference/system/xstore/functions/xstorecanacquirelicenseforstoreidresult)\
[如何使用不含套件的耐久性產品](/zh-TW/publishing/xstore-commerce/xstore-dwob)\
[授予玩家附加元件內容的存取權](/zh-TW/publishing/xstore-commerce/xstore-granting-access)


## Related topics

- [XStoreCanAcquireLicenseForStoreIdAsync](/reference/system/xstore/functions/xstorecanacquirelicenseforstoreidasync.md)
- [XStoreCanAcquireLicenseForStoreIdResult](/reference/system/xstore/functions/xstorecanacquirelicenseforstoreidresult.md)
- [XStoreCanAcquireLicenseResult](/reference/system/xstore/structs/xstorecanacquirelicenseresult.md)
- [XStoreCanLicenseStatus](/ja-jp/reference/system/xstore/enums/xstorecanlicensestatus.md)
