> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XStoreAcquireLicenseForPackageAsync

> XStoreAcquireLicenseForPackageAsync

# XStoreAcquireLicenseForPackageAsync

사용자가 사용할 자격이 있는 현재 게임에 대해 설치된 DLC 패키지(패키지가 있는 Durable 제품 형식)의 라이선스를 획득합니다.

[XStoreRegisterPackageLicenseLost](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreregisterpackagelicenselost.md)를 사용하여 이 API에서 얻은 라이선스가 손실되었는지 모니터링할 수 있습니다.

\[!NOTE] 이 API는 패키지가 없는 durable 추가 기능에는 작동하지 않습니다.
패키지가 없는 Durable에 대한 라이선스를 얻으려면 [XStoreAcquireLicenseForDurablesAsync](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreacquirelicensefordurablesasync.md)를 사용합니다.

## 구문

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

### 매개 변수

*storeContextHandle*   \_In\_\
형식: XStoreContextHandle

[XStoreCreateContext](https://docs.xbox.com/ko/reference/system/xstore/functions/xstorecreatecontext.md)가 반환한 사용자의 스토어 컨텍스트 핸들입니다.

*packageIdentifier*   \_In\_z\_\
형식: char\*

스토어 패키지를 고유하게 식별하는 문자열입니다. 패키지 식별자는 일반적으로 [XPackageEnumeratePackages](https://docs.xbox.com/ko/reference/system/xpackage/functions/xpackageenumeratepackages.md) 작업의 일부로 반환됩니다. 패키지 식별자에 대한 자세한 내용은 [다운로드 가능한 콘텐츠(DLC) 관리 및 라이선스](https://docs.xbox.com/ko/publishing/xstore-commerce/xstore-dlc.md)를 참조하세요.

*async*   \_Inout\_\
형식: [XAsyncBlock\*](https://docs.xbox.com/ko/reference/system/xasync/structs/xasyncblock.md)

수행 중인 비동기 작업을 정의하는 [XAsyncBlock](https://docs.xbox.com/ko/reference/system/xasync/structs/xasyncblock.md)입니다. [XAsyncBlock](https://docs.xbox.com/ko/reference/system/xasync/structs/xasyncblock.md)을 사용하여 호출의 상태를 폴링하고 호출 결과를 검색할 수 있습니다. 자세한 내용은 [XAsyncBlock](https://docs.xbox.com/ko/reference/system/xasync/structs/xasyncblock.md)을 참조하세요.

### 반환 값

형식: HRESULT

HRESULT 성공 또는 오류 코드입니다.

| 오류 코드 | 설명 |
| - | - |
| 0x89245208 `E_GAMEPACKAGE_NO_PACKAGE_IDENTIFIER` | 이 제품에 대한 패키지가 설치되지 않았거나, 패키지가 없는 Durable 유형에서 이 API가 호출되고 있습니다(대신 [XStoreAcquireLicenseForDurablesAsync](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreacquirelicensefordurablesasync.md)를 사용하세요). |

## 설명

패키지 라이선스와 이 함수의 실행 결과를 검색하려면 이 함수를 호출한 후 [XStoreAcquireLicenseForPackageResult](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreacquirelicenseforpackageresult.md)를 호출합니다.
패키지에 라이선스를 부여할 수 있는지 확인하려면 [XStoreCanAcquireLicenseForPackageAsync](https://docs.xbox.com/ko/reference/system/xstore/functions/xstorecanacquirelicenseforpackageasync.md)를 호출합니다.
라이선스를 획득한 후에는 [XStoreIsLicenseValid](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreislicensevalid.md)를 호출하여 유효한지 확인해야 합니다.
[XPackageMountWithUiAsync](https://docs.xbox.com/ko/reference/system/xpackage/functions/xpackagemountwithuiasync.md)는 호출될 때 라이선스를 자동으로 획득합니다.
라이선스를 획득할 수 없으면 패키지 마운트가 실패합니다.

이 코드 조각은 다음 API 사용의 예를 보여 줍니다.

* [XStoreAcquireLicenseForPackageAsync](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync.md)
* [XStoreAcquireLicenseForPackageResult](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreacquirelicenseforpackageresult.md)
* [XStoreIsLicenseValid](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreislicensevalid.md)
* [XStoreCloseLicenseHandle](https://docs.xbox.com/ko/reference/system/xstore/functions/xstorecloselicensehandle.md)
* [XStoreRegisterPackageLicenseLost](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreregisterpackagelicenselost.md)
* [XStoreUnregisterPackageLicenseLost](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreunregisterpackagelicenselost.md)

```cpp theme={null}
void CALLBACK PackageLicenseLostCallback(void* context)
{
    printf("**** License Lost ****\r\n");
}

void CALLBACK AcquireLicenseForPackageCallback(XAsyncBlock* asyncBlock)
{
    XStoreLicenseHandle licenseHandle = nullptr;

    HRESULT hr = XStoreAcquireLicenseForPackageResult(
        asyncBlock,
        &licenseHandle);

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

    bool isValid = XStoreIsLicenseValid(licenseHandle);
    printf("isValid: %s\r\n", isValid ? "true" : "false");

    if (isValid)
    {
        XTaskQueueHandle taskQueueHandle = reinterpret_cast<XTaskQueueHandle>(asyncBlock->context);
        XTaskQueueRegistrationToken token = { 0 };

        //  Todo: Save the licenseHandle to hold onto it for the life of the app or until you unload the package.
        // This allows us to be notified if the license becomes invalid and we need to handle unloading the content.
        hr = XStoreRegisterPackageLicenseLost(
            licenseHandle,
            taskQueueHandle,
            nullptr,
            PackageLicenseLostCallback,
            &token);

        if (FAILED(hr))
        {
            XStoreCloseLicenseHandle(licenseHandle);
            printf("Failed register license lost callback: 0x%x\r\n", hr);
            return;
        }

        // This would normally go in your cleanup code when releasing the license
        hr = XStoreUnregisterPackageLicenseLost(
            licenseHandle,
            token,
            true);

        if (FAILED(hr))
        {

            // This would normally go in your cleanup code when releasing the license
            XStoreCloseLicenseHandle(licenseHandle);
            printf("Failed unregister license lost callback: 0x%x\r\n", hr);
            return;
        }
    }

    XStoreCloseLicenseHandle(licenseHandle);
}

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

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

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

## 요구 사항

**헤더:** XStore.h(XGameRuntime.h에 포함됨)

**라이브러리:** xgameruntime.lib

**지원 플랫폼:** Windows, XBOX One 제품군 콘솔 및 XBOX Series 콘솔

## 개념 설명서

* [Basic store operations](https://docs.xbox.com/ko/publishing/xstore-commerce/xstore-basic-operations.md)
* [Granting players access to add-on content](https://docs.xbox.com/ko/publishing/xstore-commerce/xstore-granting-access.md)
* [Enabling licensing testing](https://docs.xbox.com/ko/publishing/xstore-commerce/xstore-licensing-setup.md)

## 참고 항목

[XStore](https://docs.xbox.com/ko/reference/system/xstore/xstore_members.md)\
[XStoreAcquireLicenseForPackageAsync](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync.md)\
[XStoreAcquireLicenseForPackageResult](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreacquirelicenseforpackageresult.md)\
[XStoreIsLicenseValid](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreislicensevalid.md)\
[XStoreCloseLicenseHandle](https://docs.xbox.com/ko/reference/system/xstore/functions/xstorecloselicensehandle.md)\
[XStoreRegisterPackageLicenseLost](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreregisterpackagelicenselost.md)\
[XStoreUnregisterPackageLicenseLost](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreunregisterpackagelicenselost.md)\
[XStoreCanAcquireLicenseForPackageAsync](https://docs.xbox.com/ko/reference/system/xstore/functions/xstorecanacquirelicenseforpackageasync.md)\
[XStoreCanAcquireLicenseForPackageResult](https://docs.xbox.com/ko/reference/system/xstore/functions/xstorecanacquirelicenseforpackageresult.md)\
[Manage and license downloadable content (DLC)](https://docs.xbox.com/ko/publishing/xstore-commerce/xstore-dlc.md)


## Related topics

- [XStoreAcquireLicenseForPackageResult](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreacquirelicenseforpackageresult.md)
- [XStoreCanAcquireLicenseForPackageAsync](https://docs.xbox.com/ko/reference/system/xstore/functions/xstorecanacquirelicenseforpackageasync.md)
- [XStoreCloseLicenseHandle](https://docs.xbox.com/ko/reference/system/xstore/functions/xstorecloselicensehandle.md)
- [XStoreUnregisterPackageLicenseLost](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreunregisterpackagelicenselost.md)
- [XStoreRegisterPackageLicenseLost](https://docs.xbox.com/ko/reference/system/xstore/functions/xstoreregisterpackagelicenselost.md)
