Función PackageIdFromFullName (appmodel.h)

Obtiene el identificador de paquete (ID) del nombre completo del paquete especificado.

Sintaxis

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

Parámetros

[in] packageFullName

Tipo: PCWSTR

Nombre completo de un paquete.

[in] flags

Tipo: const UINT32

Constantes de paquete que especifican cómo se recupera la información del paquete. Se admiten las marcas PACKAGE_INFORMATION_* .

[in, out] bufferLength

Tipo: UINT32*

En la entrada, el tamaño del búfer, en bytes. En la salida, el tamaño de los datos devueltos, en bytes.

[out, optional] buffer

Tipo: BYTE*

Identificador de paquete, representado como una estructura de PACKAGE_ID .

Valor devuelto

Tipo: LONG

Si la función se realiza correctamente, devuelve ERROR_SUCCESS. De lo contrario, la función devuelve un código de error. Los posibles códigos de error incluyen lo siguiente.

Código devuelto Descripción
ERROR_INSUFFICIENT_BUFFER
El búfer no es lo suficientemente grande como para contener los datos. BufferLength especifica el tamaño necesario.
ERROR_NOT_FOUND
El paquete no está instalado para el usuario.

Comentarios

Si las marcasespecifican PACKAGE_INFORMATION_BASIC, se recuperan los siguientes campos:

  • name
  • processorArchitecture
  • publisherId
  • resourceId
  • version
Si las marcasespecifican PACKAGE_INFORMATION_FULL, se recuperan los campos siguientes:
  • name
  • processorArchitecture
  • publisher
  • publisherId
  • resourceId
  • version
Una solicitud de PACKAGE_INFORMATION_FULL solo se realiza correctamente si el paquete correspondiente a packageFullName está instalado y accesible para el usuario actual. Si el nombre completo del paquete es sintácticamente correcto, pero no corresponde a un paquete instalado para el usuario actual y accesible, la función devuelve ERROR_NOT_FOUND.

Para obtener información sobre los límites de tamaño de cadena, consulte Constantes de identidad.

Ejemplos

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

Requisitos

Requisito Value
Cliente mínimo compatible Windows 8 [aplicaciones de escritorio | Aplicaciones para UWP]
Servidor mínimo compatible Windows Server 2012 [aplicaciones de escritorio | Aplicaciones para UWP]
Plataforma de destino Windows
Encabezado appmodel.h
Library Kernel32.lib
Archivo DLL Kernel32.dll

Vea también

GetCurrentPackageId

GetPackageId

PackageFamilyNameFromFullName

PackageFamilyNameFromId

PackageFullNameFromId

PackageNameAndPublisherIdFromFamilyName