Export (0) Print
Expand All

GetPackageApplicationIds function

Gets the IDs of apps in the specified package.

Syntax


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

Parameters

packageInfoReference [in]

Type: PACKAGE_INFO_REFERENCE

A reference to package information.

bufferLength [in, out]

Type: UINT32*

A pointer to a variable that holds the size of buffer, in bytes.

First you pass NULL to buffer to get the required size of buffer. 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: BYTE*

A pointer to memory space that receives the app IDs.

count [out, optional]

Type: UINT32*

A pointer to a variable that receives the number of app IDs in 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);

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

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

    for (int i=1; i<argc; ++i)
    {
        ProcessPackage(argv[i]);
    }
}

int ProcessPackage(_In_ PCWSTR fullName)
{
    wprintf(L"Package Full Name: %s\n", fullName);

    PACKAGE_INFO_REFERENCE pir = {0};
    LONG rc = OpenPackageInfoByFullName(fullName, 0, &pir);
    if (rc != ERROR_SUCCESS)
    {
        wprintf(L"Error %d in OpenPackageInfo\n", rc);
        return 4;
    }

    UINT32 count;
    UINT32 length = 0;
    rc = GetPackageApplicationIds(pir, &length, NULL, &count);
    if (rc != ERROR_INSUFFICIENT_BUFFER)
    {
        ClosePackageInfo(pir);
        wprintf(L"Error %u in GetPackageInfo\n", rc);
        return 2;
    }

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

    rc = GetPackageApplicationIds(pir, &length, buffer, &count);
    if (rc != ERROR_SUCCESS)
    {
        ClosePackageInfo(pir);
        wprintf(L"Error %u retrieving PackageInfo\n", rc);
        return 4;
    }
    PCWSTR * applicationUserModelIds = (PCWSTR *) buffer;
    for (UINT32 i = 0; i < count; ++i)
    {
        wprintf(L"%u: %s\n", i, applicationUserModelIds[i]);
    }

    free(buffer);

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

    return 0;
}


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:
© 2014 Microsoft