PackageFullNameFromId 函数 (appmodel.h)
获取指定包标识符的包全名 (ID) 。
语法
LONG PackageFullNameFromId(
[in] const PACKAGE_ID *packageId,
[in, out] UINT32 *packageFullNameLength,
[out, optional] PWSTR packageFullName
);
参数
[in] packageId
类型: const PACKAGE_ID*
包 ID。
[in, out] packageFullNameLength
类型: UINT32*
输入时, packageFullName 缓冲区的大小(以字符为单位)。 输出时,返回包全名的大小(以字符为单位),包括 null 终止符。
[out, optional] packageFullName
类型: PWSTR
包全名。
返回值
类型: LONG
如果函数成功,则返回 ERROR_SUCCESS。 否则,函数将返回错误代码。 可能的错误代码包括以下内容。
返回代码 | 说明 |
---|---|
|
缓冲区不够大,无法保存数据。 所需的大小由 packageFullNameLength 指定。 |
注解
有关字符串大小限制的信息,请参阅 标识常量。
示例
#define _UNICODE 1
#define UNICODE 1
#include <Windows.h>
#include <appmodel.h>
#include <malloc.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
int ShowUsage();
bool ParseArchitecture(__in PCWSTR architectureString, __out UINT32 * architecture);
bool ParseVersion(__in PCWSTR versionString, __out PACKAGE_VERSION * version);
int ShowUsage()
{
wprintf(L"Usage: PackageFullNameFromId <name><version> <arch> <resourceid> <publisher>\n");
return 1;
}
int __cdecl wmain(__in int argc, __in_ecount(argc) WCHAR * argv[])
{
if (argc <= 5)
return ShowUsage();
PACKAGE_ID packageId;
ZeroMemory(&packageId, sizeof(packageId));
packageId.name = argv[1];
if (!ParseVersion(argv[2], &packageId.version))
return 2;
if (!ParseArchitecture(argv[3], &packageId.processorArchitecture))
return 3;
packageId.resourceId = argv[4];
packageId.publisher = argv[5];
UINT32 length = 0;
LONG rc = PackageFullNameFromId(&packageId, &length, NULL);
if (rc == ERROR_SUCCESS)
{
wprintf(L"PackageFullNameFromId unexpectedly succeeded\n");
return 4;
}
else if (rc != ERROR_INSUFFICIENT_BUFFER)
{
wprintf(L"Error %d in PackageFullNameFromId\n", rc);
return 5;
}
PWSTR fullName = (PWSTR) malloc(length * sizeof(WCHAR));
if (fullName == NULL)
{
wprintf(L"Error allocating memory\n");
return 6;
}
rc = PackageFullNameFromId(&packageId, &length, fullName);
if (rc != ERROR_SUCCESS)
wprintf(L"Error %d converting Package Id to Full Name\n", rc);
else
wprintf(L"Package Full Name = %s\n", fullName);
free(fullName);
return rc == ERROR_SUCCESS ? 0 : 7;
}
bool ParseArchitecture(__in PCWSTR architectureString, __out UINT32 * architecture)
{
if (_wcsicmp(architectureString, L"neutral") == 0)
*architecture = PROCESSOR_ARCHITECTURE_NEUTRAL;
else if (_wcsicmp(architectureString, L"x86") == 0)
*architecture = PROCESSOR_ARCHITECTURE_INTEL;
else if (_wcsicmp(architectureString, L"x64") == 0)
*architecture = PROCESSOR_ARCHITECTURE_AMD64;
else if (_wcsicmp(architectureString, L"arm") == 0)
*architecture = PROCESSOR_ARCHITECTURE_ARM;
else
{
wprintf(L"Invalid architecture\n");
return false;
}
return true;
}
bool ParseVersion(__in PCWSTR versionString, __out PACKAGE_VERSION * version)
{
PWSTR s = (PWSTR) versionString;
ULONG n = wcstoul(s, &s, 10);
if (((n == 0) || (n > 65535)) && (errno == ERANGE)) {
wprintf(L"Invalid Version (Major)\n");
return false;
}
version->Major = (USHORT) n;
if (*s != L'.')
{
wprintf(L"Invalid Version\n");
return false;
}
n = wcstoul(++s, &s, 10);
if (((n == 0) || (n > 65535)) && (errno == ERANGE)) {
wprintf(L"Invalid Version (Minor)\n");
return false;
}
version->Minor = (USHORT) n;
if (*s != L'.')
{
wprintf(L"Invalid Version\n");
return false;
}
n = wcstoul(++s, &s, 10);
if (((n == 0) || (n > 65535)) && (errno == ERANGE)) {
wprintf(L"Invalid Version (Build)\n");
return false;
}
version->Build = (USHORT) n;
if (*s != L'.')
{
wprintf(L"Invalid Version\n");
return false;
}
n = wcstoul(++s, &s, 10);
if (((n == 0) || (n > 65535)) && (errno == ERANGE)) {
wprintf(L"Invalid Version (Revision)\n");
return false;
}
version->Revision = (USHORT) n;
return true;
}
要求
要求 | 值 |
---|---|
最低受支持的客户端 | Windows 8 [桌面应用 |UWP 应用] |
最低受支持的服务器 | Windows Server 2012 [桌面应用 |UWP 应用] |
目标平台 | Windows |
标头 | appmodel.h |
Library | Kernel32.lib |
DLL | Kernel32.dll |