Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

GetPackageInfo function

Gets the package information for the specified package.

Syntax


LONG WINAPI GetPackageInfo(
  _In_            PACKAGE_INFO_REFERENCE packageInfoReference,
  _In_      const UINT32                 flags,
  _Inout_         UINT32                 *bufferLength,
  _Out_opt_       BYTE                   *buffer,
  _Out_opt_       UINT32                 *count
);

Parameters

packageInfoReference [in]

Type: PACKAGE_INFO_REFERENCE

A reference to package information.

flags [in]

Type: const UINT32

The package constants that specify how package information is retrieved.

bufferLength [in, out]

Type: UINT32*

On input, the size of buffer, in bytes. On output, the size of the package information returned, in bytes.

buffer [out, optional]

Type: BYTE*

The package information, represented as an array of PACKAGE_INFO structures.

count [out, optional]

Type: UINT32*

The number of packages in the buffer.

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

The buffer is not large enough to hold the data. The required size is specified by bufferLength.

 

Examples


#define _UNICODE 1
#define UNICODE 1

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

int ShowUsage();
int ProcessPackage(__in PCWSTR fullName, __in const UINT32 flags);
void ShowPackage(__in const PACKAGE_INFO * packageInfo);

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

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

    return ProcessPackage(fullName, flags);
}

int ProcessPackage(__in PCWSTR fullName, __in const UINT32 flags)
{
    PACKAGE_INFO_REFERENCE pir = {0};
    LONG rc = OpenPackageInfoByFullName(fullName, 0, &pir);
    if (rc != ERROR_SUCCESS)
    {
        wprintf(L"Error %d in OpenPackageInfo\n", rc);
        return 2;
    }

    UINT32 count;
    UINT32 length = 0;
    rc = GetPackageInfo(pir, flags, &length, NULL, &count);
    if ((rc == ERROR_SUCCESS) && (count == 0))
    {
        ClosePackageInfo(pir);
        wprintf(L"No packages matching the filter (0x%X)\n", flags);
        return 3;
    }
    else if (rc != ERROR_INSUFFICIENT_BUFFER)
    {
        ClosePackageInfo(pir);
        wprintf(L"Error %u in GetPackageInfo\n", rc);
        return 4;
    }

    BYTE * buffer = (BYTE *) malloc(length);
    if (buffer == NULL)
    {
        ClosePackageInfo(pir);
        wprintf(L"Error allocating memory\n");
        return 5;
    }

    rc = GetPackageInfo(pir, flags, &length, buffer, &count);
    if (rc != ERROR_SUCCESS)
    {
        ClosePackageInfo(pir);
        wprintf(L"Error %u retrieving PackageInfo\n", rc);
        return 6;
    }
    const PACKAGE_INFO * packageInfo = (PACKAGE_INFO *) buffer;
    for (UINT32 i=0; i<count; ++i, ++packageInfo)
    {
        wprintf(L"Package[%u]\n", i);
        ShowPackage(packageInfo);
    }

    free(buffer);

    rc = ClosePackageInfo(pir);
    if (rc != ERROR_SUCCESS)
    {
        wprintf(L"Error %u in ClosePackageInfo\n", rc);
        return 7;
    }

    return 0;
}

void ShowPackage(__in const PACKAGE_INFO * packageInfo)
{
    wprintf(L"    ");
    UINT32 flags = packageInfo->flags;
    if ((flags & PACKAGE_FILTER_HEAD) == PACKAGE_FILTER_HEAD)
        wprintf(L"(HEAD) ");
    if ((flags & PACKAGE_FILTER_DIRECT) == PACKAGE_FILTER_DIRECT)
        wprintf(L"(DIRECT) ");
    if ((flags & PACKAGE_PROPERTY_FRAMEWORK) == PACKAGE_PROPERTY_FRAMEWORK)
        wprintf(L"(FRAMEWORK) ");
    if ((flags & PACKAGE_FILTER_RESOURCE) == PACKAGE_FILTER_RESOURCE)
        wprintf(L"(RESOURCE) ");
    if ((flags & PACKAGE_FILTER_BUNDLE) == PACKAGE_FILTER_BUNDLE)
        wprintf(L"(BUNDLE) ");
    wprintf(L"\n");

    wprintf(L"    Path        : %s\n", packageInfo->path);

    const PACKAGE_ID * packageId = &(packageInfo->packageId);
    wprintf(L"    Name        : %s\n", packageId->name);
    wprintf(L"    Publisher   : %s\n", packageId->publisher);
    wprintf(L"    PublisherId : %s\n", packageId->publisherId);
    wprintf(L"    Version     : %hu.%hu.%hu.%hu\n",
            packageId->version.Major,
            packageId->version.Minor,
            packageId->version.Build,
            packageId->version.Revision);
    wprintf(L"    Architecture: %u\n", packageId->processorArchitecture);
    if (packageId->resourceId != NULL)
        wprintf(L"    Resource    : %s\n", packageId->resourceId);
}


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

ClosePackageInfo
GetCurrentPackageInfo
GetPackagePath
OpenPackageInfoByFullName

 

 

Show:
© 2017 Microsoft