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 and/or /DIRECT\n"
            L"  fullname = Package Full Name\n");
    return 1;
}

int __cdecl wmain(__in int argc, __in_ecount(argc) WCHAR* argv[])
{
    UINT32 flags = PACKAGE_FILTER_ALL_LOADED;
    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
            {
                wprintf(L"Error: Invalid parameter (%s). Closing...", arg);
                return 2;
            }
        }
        else
        {
            break;
        }
        ++argn;
    }
    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"OpenPackageInfo failed with error %d\n", rc);
        return 4;
    }

    UINT32 count;
    UINT32 length = 0;
    rc = GetPackageInfo(pir, flags, &length, NULL, &count);
    if (rc != ERROR_INSUFFICIENT_BUFFER)
    {
        ClosePackageInfo(pir);
        wprintf(L"GetPackageInfo failed with error %d\n", rc);
        return 2;
    }

    BYTE * buffer = (BYTE *) malloc(length);
    if (buffer == NULL)
    {
        ClosePackageInfo(pir);
        wprintf(L"Memory allocation failed\n");
        return 3;
    }

    rc = GetPackageInfo(pir, flags, &length, buffer, &count);
    if (rc != ERROR_SUCCESS)
    {
        ClosePackageInfo(pir);
        wprintf(L"GetPackageInfo failed with error %d\n", rc);
        return 4;
    }
    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"ClosePackageInfo failed with error %d\n", rc);
        return 3;
    }

    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) ");
    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"    Publisher ID : %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:
© 2014 Microsoft