FindPackagesByPackageFamily function

Finds the packages with the specified family name for the current user.

Syntax


LONG WINAPI FindPackagesByPackageFamily(
  _In_      PCWSTR packageFamilyName,
  _In_      UINT32 packageFilters,
  _Inout_   UINT32 *count,
  _Out_opt_ PWSTR  *packageFullNames,
  _Inout_   UINT32 *bufferLength,
  _Out_opt_ WCHAR  *buffer,
  _Out_opt_ UINT32 *packageProperties
);

Parameters

packageFamilyName [in]

Type: PCWSTR

The package family name.

packageFilters [in]

Type: UINT32

The package constants that specify how package information is retrieved. All package constants except PACKAGE_FILTER_ALL_LOADED are supported.

count [in, out]

Type: UINT32*

A pointer to a variable that holds the number of package full names that were found.

First you pass NULL to packageFullNames to get the number of package full names that were found. You use this number to allocate memory space for packageFullNames. Then you pass the address of this memory space to fill packageFullNames.

packageFullNames [out, optional]

Type: PWSTR*

A pointer to memory space that receives the strings of package full names that were found.

bufferLength [in, out]

Type: UINT32*

A pointer to a variable that holds the number of characters in the string of package full names.

First you pass NULL to buffer to get the number of characters. You use this number to allocate memory space for buffer. Then you pass the address of this memory space to fill buffer.

buffer [out, optional]

Type: WCHAR*

A pointer to memory space that receives the string of characters for all of the package full names.

packageProperties [out, optional]

Type: UINT32*

A pointer to memory space that receives the package properties for all of the packages that were found.

Return value

Type: LONG

If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes include the following.

Return codeDescription
ERROR_INSUFFICIENT_BUFFER

One or more buffer is not large enough to hold the data. The required size is specified by either count or buffer.

 

Examples


#define _UNICODE 1
#define UNICODE 1

#include <Windows.h>
#include <appmodel.h>
#include <malloc.h>
#include <stdio.h>

int ShowUsage();
void LookupFamilyName(_In_ PCWSTR familyName, _In_ const UINT32 filter);
PCWSTR PackagePropertiesToString(_In_ const UINT32 properties);

int ShowUsage()
{
    wprintf(L"Usage: FindPackagesByPackageFamily [options] <familyname> [<familyname>...]\n"
            L"where\n"
            L"     options = HEAD, DIRECT, RESOURCE and/or BUNDLE\n"
            L"  familyname = Package Family Name\n");
    return 1;
}

int __cdecl wmain(_In_ int argc, _In_reads_(argc) WCHAR * argv[])
{
    UINT32 filter = 0;
    int argn = 1;
    while (argn < argc)
    {
        PCWSTR arg = argv[argn];
        if (*arg == L'/')
        {
            if (_wcsicmp(arg + 1, L"HEAD") == 0)
            {
                filter |= PACKAGE_FILTER_HEAD;
            }
            else if (_wcsicmp(arg + 1, L"DIRECT") == 0)
            {
                filter |= PACKAGE_FILTER_DIRECT;
            }
            else if (_wcsicmp(arg + 1, L"RESOURCE") == 0)
            {
                filter |= PACKAGE_FILTER_RESOURCE;
            }
            else if (_wcsicmp(arg + 1, L"BUNDLE") == 0)
            {
                filter |= PACKAGE_FILTER_BUNDLE;
            }
            else
            {
                wprintf(L"Error: Invalid parameter (%s), aborting...", arg);
                return 2;
            }
        }
        else
        {
            break;
        }
        ++argn;
    }
    if (filter == 0)
    {
        filter = PACKAGE_FILTER_HEAD | PACKAGE_FILTER_DIRECT | PACKAGE_FILTER_RESOURCE | PACKAGE_FILTER_BUNDLE;
    }
    if (argn >= argc)
    {
        return ShowUsage();
    }
    for (; argn < argc; ++argn)
    {
        PCWSTR familyName = argv[argn];
        LookupFamilyName(familyName, filter);
    }

    return 0;
}

void LookupFamilyName(_In_ PCWSTR familyName, _In_ const UINT32 filter)
{
    wprintf(L"Family Name: %s\n", familyName);
    UINT32 count = 0;
    UINT32 length = 0;
    LONG rc = FindPackagesByPackageFamily(familyName, filter, &count, nullptr, &length, nullptr, nullptr);
    if (rc == ERROR_SUCCESS)
    {
        wprintf(L"No packages found\n");
        return;
    }
    else if (rc != ERROR_INSUFFICIENT_BUFFER)
    {
        wprintf(L"Error %d in FindPackagesByPackageFamily\n", rc);
        return;
    }

    PWSTR * fullNames = (PWSTR *) malloc(count * sizeof(*fullNames));
    if (fullNames == nullptr)
    {
        wprintf(L"Error allocating memory\n");
        return;
    }

    PWSTR buffer = (PWSTR) malloc(length * sizeof(WCHAR));
    if (buffer == nullptr)
    {
        wprintf(L"Error allocating memory\n");
        return;
    }

    UINT32 * properties = (UINT32 *) malloc(count * sizeof(*properties));
    if (properties == nullptr)
    {
        wprintf(L"Error allocating memory\n");
        return;
    }

    rc = FindPackagesByPackageFamily(familyName, filter, &count, fullNames, &length, buffer, properties);
    if (rc != ERROR_SUCCESS)
    {
        wprintf(L"Error %d looking up Full Names from Family Names\n", rc);
    }
    else
    {
        for (UINT32 index = 0; index < count; ++index)
        {
            wprintf(L"%u: %s [0x%X %s]\n",
                    index, fullNames[index], properties[index], PackagePropertiesToString(properties[index]));
        }
    }

    free(properties);
    free(buffer);
    free(fullNames);
}

PCWSTR PackagePropertiesToString(_In_ const UINT32 properties)
{
    const UINT32 PACKAGE_PROPERTY_APPLICATION = 0;
    const UINT32 mask = PACKAGE_PROPERTY_APPLICATION | PACKAGE_PROPERTY_FRAMEWORK |
                        PACKAGE_PROPERTY_RESOURCE | PACKAGE_PROPERTY_BUNDLE;
    switch (properties & mask)
    {
        case PACKAGE_PROPERTY_APPLICATION: return L"Application";
        case PACKAGE_PROPERTY_FRAMEWORK:   return L"Framework";
        case PACKAGE_PROPERTY_RESOURCE:    return L"Resource";
        case PACKAGE_PROPERTY_BUNDLE:      return L"Bundle";
        default:                           return L"?";
    }
}


Requirements

Minimum supported client

Windows 8.1 [desktop apps only]

Minimum supported server

Windows Server 2012 R2 [desktop apps only]

Header

AppModel.h

Library

Kernel32.lib

DLL

Kernel32.dll

 

 

Show: