Partage via


XPackageRegisterPackageInstalled

Registers a callback to be called when an installation is completed.

Syntax

HRESULT XPackageRegisterPackageInstalled(  
         XTaskQueueHandle queue,  
         void* context,  
         XPackageInstalledCallback* callback,  
         XTaskQueueRegistrationToken* token  
)  

Parameters

queue   _In_
Type: XTaskQueueHandle

The asynchronous queue on which the callback is to run.

context   _In_opt_
Type: void*

Context to be passed to the callback.

callback   _In_
Type: XPackageInstalledCallback*

User-defined callback to be called when an installation is completed.

token   _Out_
Type: XTaskQueueRegistrationToken*

On return, contains a token that identifies the callback that can be used to unregister the callback with XPackageUnregisterPackageInstalled.

Return value

Type: HRESULT

HRESULT success or error code.

Remarks

PackageInstalled notifications can be used to determine when a new package is fully installed.

Both the XPackageEnumeratePackages API and XPackageRegisterPackageInstalled API provide details about an installation, through an XPackageDetails structure. If the package is installing, the installing property is set to true and you can create an installation monitor, to let the package's identifier monitor the progress of installation.

There are no generic installation queue notifications; the intent is to use XPackageEnumeratePackages to show and track items in flight, and to use PackageInstalled to announce the presence of new DLC. Nor is there an API to stop, start, or cancel an installation. From a game's perspective, the installation should take care of itself. Errors are automatically retried and invisible to the game.

In the following example, XPackageRegisterPackageInstalled is used to print a message when a new DLC package is installed:

void CALLBACK NewPackageAdded(void* /* context */, const XPackageDetails* details)
{
    if (details->kind == XPackageKind::Content)
    {
        printf("Package added: %s\n", details->displayName);
    }
}

HRESULT ListenForNewDlc(XTaskQueueHandle queue, XTaskQueueRegistrationToken* token)
{
    HRESULT hr = XPackageRegisterPackageInstalled(queue, nullptr, NewPackageAdded, token);
    return hr;
}

void StopListeningForDlc(XTaskQueueRegistrationToken token)
{
    XPackageUnregisterPackageInstalled(token, false);
}

Requirements

Header: XPackage.h

Library: xgameruntime.lib

Supported platforms: Windows, Xbox One family consoles and Xbox Series consoles

See also

XPackage