Share via


Funzione PackageIdFromFullName (appmodel.h)

Ottiene l'identificatore del pacchetto (ID) per il nome completo del pacchetto specificato.

Sintassi

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

Parametri

[in] packageFullName

Tipo: PCWSTR

Nome completo di un pacchetto.

[in] flags

Tipo: const UINT32

Costanti del pacchetto che specificano il modo in cui vengono recuperate le informazioni sul pacchetto. I flag PACKAGE_INFORMATION_* sono supportati.

[in, out] bufferLength

Tipo: UINT32*

In input, le dimensioni del buffer, in byte. In output, le dimensioni dei dati restituiti in byte.

[out, optional] buffer

Tipo: BYTE*

ID pacchetto, rappresentato come struttura PACKAGE_ID .

Valore restituito

Tipo: LONG

Se la funzione ha esito positivo, restituisce ERROR_SUCCESS. In caso contrario, la funzione restituisce un codice di errore. I codici di errore possibili includono quanto segue.

Codice restituito Descrizione
ERROR_INSUFFICIENT_BUFFER
Il buffer non è abbastanza grande per contenere i dati. Le dimensioni necessarie sono specificate da bufferLength.
ERROR_NOT_FOUND
Il pacchetto non è installato per l'utente.

Commenti

Se i flagspecificano PACKAGE_INFORMATION_BASIC, vengono recuperati i campi seguenti:

  • nome
  • processorArchitecture
  • publisherId
  • resourceId
  • version
Se i flagspecificano PACKAGE_INFORMATION_FULL, vengono recuperati i campi seguenti:
  • nome
  • processorArchitecture
  • Editore
  • publisherId
  • resourceId
  • version
Una richiesta di PACKAGE_INFORMATION_FULL ha esito positivo solo se il pacchetto corrispondente a packageFullName è installato per e accessibile all'utente corrente. Se il nome completo del pacchetto è sintatticamente corretto, ma non corrisponde a un pacchetto installato per e accessibile all'utente corrente, la funzione restituisce ERROR_NOT_FOUND.

Per informazioni sui limiti delle dimensioni delle stringhe, vedere Costanti di identità.

Esempio

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

Requisiti

Requisito Valore
Client minimo supportato Windows 8 [app desktop | App UWP]
Server minimo supportato Windows Server 2012 [app desktop | App UWP]
Piattaforma di destinazione Windows
Intestazione appmodel.h
Libreria Kernel32.lib
DLL Kernel32.dll

Vedere anche

GetCurrentPackageId

GetPackageId

PackageFamilyNameFromFullName

PackageFamilyNameFromId

PackageFullNameFromId

PackageNameAndPublisherIdFromFamilyName