PackageIdFromFullName, fonction (appmodel.h)

Obtient l’identificateur de package (ID) pour le nom complet du package spécifié.

Syntaxe

LONG PackageIdFromFullName(
  [in]            PCWSTR       packageFullName,
  [in]            const UINT32 flags,
  [in, out]       UINT32       *bufferLength,
  [out, optional] BYTE         *buffer
);

Paramètres

[in] packageFullName

Type : PCWSTR

Nom complet d’un package.

[in] flags

Type : const UINT32

Constantes de package qui spécifient la façon dont les informations de package sont récupérées. Les indicateurs PACKAGE_INFORMATION_* sont pris en charge.

[in, out] bufferLength

Type : UINT32*

En entrée, taille de la mémoire tampon, en octets. En sortie, taille des données retournées, en octets.

[out, optional] buffer

Type : BYTE*

L’ID de package, représenté sous la forme d’une structure PACKAGE_ID .

Valeur retournée

Type : LONG

Si la fonction réussit, elle retourne ERROR_SUCCESS. Sinon, la fonction retourne un code d’erreur. Les codes d’erreur possibles sont les suivants.

Code de retour Description
ERROR_INSUFFICIENT_BUFFER
La mémoire tampon n’est pas assez grande pour contenir les données. La taille requise est spécifiée par bufferLength.
ERROR_NOT_FOUND
Le package n’est pas installé pour l’utilisateur.

Remarques

Si indicateurs spécifie PACKAGE_INFORMATION_BASIC, les champs suivants sont récupérés :

  • name
  • processorArchitecture
  • publisherId
  • resourceId
  • version
Si indicateurs spécifie PACKAGE_INFORMATION_FULL, les champs suivants sont récupérés :
  • name
  • processorArchitecture
  • publisher
  • publisherId
  • resourceId
  • version
Une demande de PACKAGE_INFORMATION_FULL réussit uniquement si le package correspondant à packageFullName est installé pour l’utilisateur actuel et accessible. Si le nom complet du package est syntaxiquement correct, mais ne correspond pas à un package installé pour l’utilisateur actuel et accessible à celui-ci, la fonction retourne ERROR_NOT_FOUND.

Pour plus d’informations sur les limites de taille de chaîne, consultez Constantes d’identité.

Exemples

#define _UNICODE 1
#define UNICODE 1

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

int ShowUsage();
void FullNameToId(__in PCWSTR fullName, __in const UINT32 flags);
void ShowPackageId(__in const PACKAGE_ID * packageId);

int ShowUsage()
{
    wprintf(L"Usage: PackageIdFromFullName <[flags]fullname> [<[flags]fullname>...]\n"
            L"flags:\n"
            L"    ? = Basic information (PACKAGE_INFORMATION_BASIC)\n"
            L"    * = Full information (PACKAGE_INFORMATION_FULL)\n"
            L"Default = Basic\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)
    {
        PCWSTR fullName = argv[i];
        UINT32 flags = PACKAGE_INFORMATION_BASIC;
        if (*fullName != L'\0')
        {
            if (*fullName == L'?')
            {
                flags = PACKAGE_INFORMATION_BASIC;
                ++fullName;
            }
            else if (*fullName == L'*')
            {
                flags = PACKAGE_INFORMATION_FULL;
                ++fullName;
            }
        }
        FullNameToId(fullName, flags);
    }

    return 0;
}

void FullNameToId(__in PCWSTR fullName, __in const UINT32 flags)
{
    wprintf(L"FullName: %s%s\n", fullName, ((flags & PACKAGE_INFORMATION_FULL) == 0 ? L"  [BASIC]" : L"  [FULL]"));
    UINT32 length = 0;
    LONG rc = PackageIdFromFullName(fullName, flags, &length, NULL);
    if (rc == ERROR_SUCCESS)
    {
        wprintf(L"PackageIdFromFullName unexpected succeeded\n");
        return;
    }
    else if (rc != ERROR_INSUFFICIENT_BUFFER)
    {
        wprintf(L"Error %d in PackageIdFromFullName\n", rc);
        return;
    }

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

    rc = PackageIdFromFullName(fullName, flags, &length, buffer);
    if (rc != ERROR_SUCCESS)
        wprintf(L"Error %d converting Package Full Name to Id\n", rc);
    else
    {
        ShowPackageId((PACKAGE_ID *) buffer);
    }

    free(buffer);
}

void ShowPackageId(__in const PACKAGE_ID * packageId)
{
    wprintf(L"    Name        : %s\n", packageId->name);
    if (packageId->publisher != NULL)
        wprintf(L"    Publisher   : %s\n", packageId->publisher);
    if (packageId->publisherId != NULL)
        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);
}

Configuration requise

Condition requise Valeur
Client minimal pris en charge Windows 8 [applications de bureau | Applications UWP]
Serveur minimal pris en charge Windows Server 2012 [applications de bureau | Applications UWP]
Plateforme cible Windows
En-tête appmodel.h
Bibliothèque Kernel32.lib
DLL Kernel32.dll

Voir aussi

GetCurrentPackageId

GetPackageId

PackageFamilyNameFromFullName

PackageFamilyNameFromId

PackageFullNameFromId

PackageNameAndPublisherIdFromFamilyName