|
| 1 | +--- |
| 2 | +UID: NF:appmodel.AddPackageDependency2 |
| 3 | +title: AddPackageDependency2 |
| 4 | +description: Resolves a previously defined package dependency to a specific package, and adds it to the invoking process' package graph. After the dependency has been added, other code-loading methods (such as LoadLibrary and CoCreateInstance) can find the binaries in the resolved package. |
| 5 | +ms.date: 02/05/2025 |
| 6 | +tech.root: appxpkg |
| 7 | +targetos: Windows |
| 8 | +req.assembly: |
| 9 | +req.construct-type: function |
| 10 | +req.ddi-compliance: |
| 11 | +req.dll: |
| 12 | +req.header: appmodel.h |
| 13 | +req.idl: |
| 14 | +req.include-header: |
| 15 | +req.irql: |
| 16 | +req.kmdf-ver: |
| 17 | +req.lib: |
| 18 | +req.max-support: |
| 19 | +req.namespace: |
| 20 | +req.redist: |
| 21 | +req.target-min-winverclnt: Windows 11, version 23H2 (10.0; Build 22631) |
| 22 | +req.target-min-winversvr: |
| 23 | +req.target-type: |
| 24 | +req.type-library: |
| 25 | +req.umdf-ver: |
| 26 | +req.unicode-ansi: |
| 27 | +topic_type: |
| 28 | + - apiref |
| 29 | +api_type: |
| 30 | + - HeaderDef |
| 31 | +api_location: |
| 32 | + - appmodel.h |
| 33 | +api_name: |
| 34 | + - AddPackageDependency2 |
| 35 | +f1_keywords: |
| 36 | + - AddPackageDependency2 |
| 37 | + - appmodel/AddPackageDependency2 |
| 38 | +dev_langs: |
| 39 | + - c++ |
| 40 | +--- |
| 41 | + |
| 42 | +## -description |
| 43 | + |
| 44 | +Adds a run-time reference for the framework package dependency you created earlier by using the [TryCreatePackageDependency](./nf-appmodel-trycreatepackagedependency.md) method, with the specified options. After this method successfully returns, your app can activate types and use content from the framework package. |
| 45 | + |
| 46 | +## -parameters |
| 47 | + |
| 48 | +### -param packageDependencyId |
| 49 | + |
| 50 | +Type: <b>PCWSTR</b> |
| 51 | + |
| 52 | +The ID of the package dependency to be resolved and added to the invoking process' package graph. This parameter must match a package dependency defined by using the [TryCreatePackageDependency](nf-appmodel-trycreatepackagedependency.md) function for the calling user or the system (via the [CreatePackageDependencyOptions_ScopeIsSystem](ne-appmodel-createpackagedependencyoptions.md) option), or else an error is returned. |
| 53 | + |
| 54 | +### -param rank |
| 55 | + |
| 56 | +Type: <b>INT32</b> |
| 57 | + |
| 58 | +The rank to use to add the resolved package to the caller's package graph. For more information, see **Remarks**. |
| 59 | + |
| 60 | +### -param options |
| 61 | + |
| 62 | +Type: <b><a href="./ne-appmodel-addpackagedependencyoptions2.md">AddPackageDependencyOptions2</a></b> |
| 63 | + |
| 64 | +The options to apply when adding the package dependency. |
| 65 | + |
| 66 | +### -param packageDependencyContext |
| 67 | + |
| 68 | +Type: <b>PACKAGEDEPENDENCY_CONTEXT*</b> |
| 69 | + |
| 70 | +The handle of the added package dependency. This handle is valid until it is passed to <a href="nf-appmodel-removepackagedependency.md">RemovePackageDependency</a>. |
| 71 | + |
| 72 | +### -param packageFullName |
| 73 | + |
| 74 | +Type: <b>PCWSTR*</b> |
| 75 | + |
| 76 | +When this method returns, contains the address of a pointer to a null-terminated Unicode string that specifies the full name of the package to which the dependency has been resolved. The caller is responsible for freeing this resource once it is no longer needed by calling [HeapFree](/windows/win32/api/heapapi/nf-heapapi-heapfree). |
| 77 | + |
| 78 | +## -returns |
| 79 | + |
| 80 | +Type: <b>HRESULT</b> |
| 81 | + |
| 82 | +If the function succeeds it returns <b>ERROR_SUCCESS</b>. Otherwise, the function returns an error code. The possible error codes include the following. |
| 83 | + |
| 84 | +| Return code | Description | |
| 85 | +|-------------|-------------| |
| 86 | +| E_INVALIDARG | The *packageDependencyId* or *packageDependencyContext* parameter is NULL on input. | |
| 87 | + |
| 88 | +## -remarks |
| 89 | + |
| 90 | +See **Remarks** for [AddPackageDependency](./nf-appmodel-addpackagedependency.md). |
| 91 | + |
| 92 | +## -see-also |
| 93 | + |
| 94 | +* [RemovePackageDependency](./nf-appmodel-removepackagedependency.md) |
| 95 | +* [TryCreatePackageDependency](./nf-appmodel-trycreatepackagedependency.md) |
| 96 | +* [Use the dynamic dependency API to reference MSIX packages at run time](/windows/apps/desktop/modernize/framework-packages/use-the-dynamic-dependency-api) |
0 commit comments