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

# XStoreRegisterPackageLicenseLost

> XStoreRegisterPackageLicenseLost

# XStoreRegisterPackageLicenseLost

为许可证丢失事件注册回调。
使用此 API 注册通过 [XStoreAcquireLicenseForPackageAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync.md) 和 [XStoreAcquireLicenseForDurablesAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreacquirelicensefordurablesasync.md) 获得的耐用型许可证。

## 语法

```cpp theme={null}
HRESULT XStoreRegisterPackageLicenseLost(  
         XStoreLicenseHandle licenseHandle,  
         XTaskQueueHandle queue,  
         void* context,  
         XStorePackageLicenseLostCallback* callback,  
         XTaskQueueRegistrationToken* token  
)  
```

### 参数

*licenseHandle*   \_In\_\
类型：XStoreLicenseHandle

要为其注册回调的许可证句柄。

*queue*   \_In\_\
类型：XTaskQueueHandle

用于处理异步工作的异步队列。

*context*   \_In\_opt\_\
类型：void\*

要传递给回调的游戏定义上下文。

*callback*   \_In\_\
类型：XStorePackageLicenseLostCallback\*

要注册的回调。

*token*   \_Out\_\
类型：[XTaskQueueRegistrationToken\*](https://docs.xbox.com/zh-CN/reference/system/xtaskqueue/structs/xtaskqueueregistrationtoken.md)

成功时，包含用于标识回调的令牌。

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

## 备注

此函数注册由 [XStorePackageLicenseLostCallback](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorepackagelicenselostcallback.md) 定义的回调函数。
下一次发生耐用型许可证丢失事件时，将调用已注册的回调函数。
注册期间不会调用该回调函数。
当购买账户从设备注销并且其先前共享的许可证不再可供当前用户使用时，通常会发生许可证丢失事件。
为避免内存泄漏，当你使用完回调函数后，必须调用 [XStoreUnregisterPackageLicenseLost](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreunregisterpackagelicenselost.md)。

由于用户更改、网络更改、并发检查或许可证在设备上过期，耐用型许可证可能随时丢失。
游戏应注册许可证丢失事件，并在触发回调时尝试重新获取耐用型产品的许可证。
许可证丢失事件有助于检测系统何时错误地向当前玩家返回属于另一账户的缓存许可证。
在这种情况下，许可证丢失事件将立即触发，并且当再次调用 XStoreAcquireLicense\* 时，将提供新的许可证。

有关使用示例，请参阅 [XStoreAcquireLicenseForPackageAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync.md)。

## 要求

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

**库：** xgameruntime.lib

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

## 概念文档

* [授予玩家访问加载项内容的权限](https://docs.xbox.com/zh-CN/publishing/xstore-commerce/xstore-granting-access.md)
* [启用许可测试](https://docs.xbox.com/zh-CN/publishing/xstore-commerce/xstore-licensing-setup.md)

## 另请参阅

[XStore](https://docs.xbox.com/zh-CN/reference/system/xstore/xstore_members.md)\
[XStoreAcquireLicenseForPackageAsync](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync.md)\
[XStoreAcquireLicenseForPackageResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreacquirelicenseforpackageresult.md)\
[XStoreIsLicenseValid](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreislicensevalid.md)\
[XStoreCloseLicenseHandle](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorecloselicensehandle.md)\
[XStorePackageLicenseLostCallback](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorepackagelicenselostcallback.md)\
[XStoreUnregisterPackageLicenseLost](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreunregisterpackagelicenselost.md)\
[授予玩家访问加载项内容的权限](https://docs.xbox.com/zh-CN/publishing/xstore-commerce/xstore-granting-access.md)


## Related topics

- [XStorePackageLicenseLostCallback](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorepackagelicenselostcallback.md)
- [XStoreUnregisterPackageLicenseLost](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreunregisterpackagelicenselost.md)
- [XStoreAcquireLicenseForPackageResult](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreacquirelicenseforpackageresult.md)
- [XStoreCloseLicenseHandle](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstorecloselicensehandle.md)
- [XStoreIsLicenseValid](https://docs.xbox.com/zh-CN/reference/system/xstore/functions/xstoreislicensevalid.md)
