GetPackagesByPackageFamily function

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

Syntax


LONG WINAPI GetPackagesByPackageFamily(
  _In_       PWSTR packageFamilyName,
  _Inout_    UINT32 *count,
  _Out_opt_  PWSTR *packageFullNames,
  _Inout_    UINT32 *bufferLength,
  _Out_opt_  WCHAR *buffer
);

Parameters

packageFamilyName [in]

Type: PWSTR

The package family name.

count [in, out]

Type: UINT32*

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

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

packageFullNames [out, optional]

Type: PWSTR*

A pointer to the strings of package full names.

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 number to fill buffer.

buffer [out, optional]

Type: WCHAR*

The string of characters for all of the package full names.

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);

int ShowUsage()
{
    wprintf(L"Usage: GetPackagesByPackageFamily <familyname> [<familyname>...]\n");
    return 1;
}

int __cdecl wmain(__in int argc, __in_ecount(argc) WCHAR * argv[])
{
    if (argc <= 1)
        return ShowUsage();

    for (int i=1; i<argc; ++i)
        LookupFamilyName(argv[i]);

    return 0;
}

void LookupFamilyName(__in PCWSTR familyName)
{
    wprintf(L"Family Name: %s\n", familyName);
    UINT32 count = 0;
    UINT32 length = 0;
    LONG rc = GetPackagesByPackageFamily(familyName, &count, NULL, &length, NULL);
    if (rc == ERROR_SUCCESS)
    {
        wprintf(L"No packages found\n");
        return;
    }
    else if (rc != ERROR_INSUFFICIENT_BUFFER)
    {
        wprintf(L"GetPackagesByPackageFamily failed with error %d\n", rc);
        return;
    }

    PWSTR * fullNames = (PWSTR *) malloc(count * sizeof(*fullNames));
    if (fullNames == NULL)
    {
        wprintf(L"Memory allocation failed\n");
        return;
    }

    PWSTR buffer = (PWSTR) malloc(length * sizeof(WCHAR));
    if (buffer == NULL)
    {
        wprintf(L"Memory allocation failed\n");
        return;
    }

    rc = GetPackagesByPackageFamily(familyName, &count, fullNames, &length, buffer);
    if (rc != ERROR_SUCCESS)
        wprintf(L"GetPackagesByPackageFamily failed with error %d\n", rc);
    else
    {
        for (UINT32 i = 0; i < count; ++i)
            wprintf(L"%u: Full name = %s\n", i, fullNames[i]);
    }

    free(buffer);
    free(fullNames);
}

Requirements

Minimum supported client

Windows 8 [desktop apps only]

Minimum supported server

Windows Server 2012 [desktop apps only]

Header

AppModel.h

Library

Kernel32.lib

DLL

Kernel32.dll

See also

PackageNameAndPublisherIdFromFamilyName

 

 

Show:
© 2014 Microsoft