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

# XStoreRegisterPackageLicenseLost

> XStoreRegisterPackageLicenseLost

# XStoreRegisterPackageLicenseLost

为许可证丢失事件注册回调。
使用此 API 注册通过 [XStoreAcquireLicenseForPackageAsync](/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync) 和 [XStoreAcquireLicenseForDurablesAsync](/reference/system/xstore/functions/xstoreacquirelicensefordurablesasync) 获得的耐用型许可证。

## 语法

```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\*](/reference/system/xtaskqueue/structs/xtaskqueueregistrationtoken)

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

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

## 备注

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

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

有关使用示例，请参阅 [XStoreAcquireLicenseForPackageAsync](/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync)。

## 要求

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

**库：** xgameruntime.lib

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

## 概念文档

* [授予玩家访问加载项内容的权限](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-granting-access-to-content)
* [启用许可测试](/publishing/xstore-commerce/xstore-licensing-setup)

## 另请参阅

[XStore](/reference/system/xstore/xstore_members)\
[XStoreAcquireLicenseForPackageAsync](/reference/system/xstore/functions/xstoreacquirelicenseforpackageasync)\
[XStoreAcquireLicenseForPackageResult](/reference/system/xstore/functions/xstoreacquirelicenseforpackageresult)\
[XStoreIsLicenseValid](/reference/system/xstore/functions/xstoreislicensevalid)\
[XStoreCloseLicenseHandle](/reference/system/xstore/functions/xstorecloselicensehandle)\
[XStorePackageLicenseLostCallback](/reference/system/xstore/functions/xstorepackagelicenselostcallback)\
[XStoreUnregisterPackageLicenseLost](/reference/system/xstore/functions/xstoreunregisterpackagelicenselost)\
[授予玩家访问加载项内容的权限](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-granting-access-to-content)


## Related topics

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