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

# XStoreCanAcquireLicenseForPackageAsync

> XStoreCanAcquireLicenseForPackageAsync

# XStoreCanAcquireLicenseForPackageAsync

擷取 DLC (含套件的耐久性產品) 的預覽授權。
此 API 可讓遊戲查看耐久性產品的套件是否可授權，但不會實際取得授權。

## 語法

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

### 參數

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

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

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

唯一識別市集套件的字串。如需套件識別碼的詳細資訊，請參閱[管理及授權可下載內容 (DLC)](/zh-TW/publishing/xstore-commerce/xstore-dlc)。

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

## 備註

若要擷取預覽授權及此函式的執行結果，請在呼叫此函式之後呼叫 [XStoreCanAcquireLicenseForPackageResult](/zh-TW/reference/system/xstore/functions/xstorecanacquirelicenseforpackageresult)。
此函式需要線上連線，而且只會檢查是否可以取得套件的授權。
若要取得套件的授權，請呼叫 [XStoreAcquireLicenseForPackageAsync](/zh-TW/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync)。

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

* [XStoreCanAcquireLicenseForPackageAsync](/zh-TW/reference/system/xstore/functions/xstorecanacquirelicenseforpackageasync)
* [XStoreCanAcquireLicenseForPackageResult](/zh-TW/reference/system/xstore/functions/xstorecanacquirelicenseforpackageresult)

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

    HRESULT hr = XStoreCanAcquireLicenseForPackageResult(
        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 CanAcquireLicenseForPackage(XStoreContextHandle storeContextHandle, XTaskQueueHandle taskQueueHandle, const char* packageIdentifier)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = taskQueueHandle;
    asyncBlock->callback = CanAcquireLicenseForPackageCallback;

    HRESULT hr = XStoreCanAcquireLicenseForPackageAsync(
        storeContextHandle,
        packageIdentifier,
        asyncBlock.get());

    if (FAILED(hr))
    {
        printf("Failed to get preview license for package: 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)\
[XStoreCanAcquireLicenseForPackageResult](/zh-TW/reference/system/xstore/functions/xstorecanacquirelicenseforpackageresult)\
[XStoreAcquireLicenseForPackageAsync](/zh-TW/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync)\
[管理及授權可下載內容 (DLC)](/zh-TW/publishing/xstore-commerce/xstore-dlc)


## Related topics

- [XStoreCanAcquireLicenseForPackageAsync](/reference/system/xstore/functions/xstorecanacquirelicenseforpackageasync.md)
- [XStoreCanAcquireLicenseForPackageResult](/reference/system/xstore/functions/xstorecanacquirelicenseforpackageresult.md)
