GetCurrentPackageInfo function
Gets the package information for the calling process.
Syntax
LONG WINAPI GetCurrentPackageInfo(
_In_ const UINT32 flags,
_Inout_ UINT32 *bufferLength,
_Out_opt_ BYTE *buffer,
_Out_opt_ UINT32 *count
);
Parameters
- flags [in]
-
Type: const UINT32
The package constants that specify how package information is retrieved. The PACKAGE_FILTER_* flags are supported.
- bufferLength [in, out]
-
Type: UINT32*
On input, the size of buffer, in bytes. On output, the size of the array of structures returned, in bytes.
- buffer [out, optional]
-
Type: BYTE*
The package information, represented as an array of PACKAGE_INFO structures.
- count [out, optional]
-
Type: UINT32*
The number of structures in the 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 code | Description |
|---|---|
|
The process has no package identity. |
|
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(); void ShowPackage(__in const PACKAGE_INFO * packageInfo); int ShowUsage() { wprintf(L"Usage: GetCurrentPackageInfo [options]\n" L"where\n" L" options = HEAD, DIRECT, RESOURCE and/or BUNDLE\n"); return 1; } int __cdecl wmain(__in int argc, __in_ecount(argc) WCHAR* argv[]) { UINT32 flags; if (argc < 2) flags = PACKAGE_FILTER_HEAD | PACKAGE_FILTER_DIRECT | PACKAGE_FILTER_RESOURCE | PACKAGE_FILTER_BUNDLE; else { flags = 0; for (int i = 1; i < argc; ++i) { if (_wcsicmp(argv[i], L"HEAD")) flags |= PACKAGE_FILTER_HEAD; else if (_wcsicmp(argv[i], L"DIRECT")) flags |= PACKAGE_FILTER_DIRECT; else if (_wcsicmp(argv[i], L"RESOURCE")) flags |= PACKAGE_FILTER_RESOURCE; else if (_wcsicmp(argv[i], L"BUNDLE")) flags |= PACKAGE_FILTER_BUNDLE; else return ShowUsage(); } } UINT32 count; UINT32 length = 0; LONG rc = GetCurrentPackageInfo(flags, &length, NULL, &count); if (rc != ERROR_INSUFFICIENT_BUFFER) { if (rc == APPMODEL_ERROR_NO_PACKAGE) wprintf(L"Process has no package identity\n"); else wprintf(L"Error %d in GetCurrentPackageInfo\n", rc); return 2; } BYTE * buffer = (BYTE *) malloc(length); if (buffer == NULL) { wprintf(L"Error allocating memory\n"); return 3; } rc = GetCurrentPackageInfo(flags, &length, buffer, &count); if (rc != ERROR_SUCCESS) { wprintf(L"Error %d retrieving PackageInfo\n", rc); return 4; } const PACKAGE_INFO * packageInfo = (PACKAGE_INFO *) buffer; for (UINT32 i=0; i<count; ++i, ++packageInfo) { wprintf(L"Package[%u]\n", i); ShowPackage(packageInfo); } free(buffer); return 0; } void ShowPackage(__in const PACKAGE_INFO * packageInfo) { wprintf(L" "); UINT32 flags = packageInfo->flags; if ((flags & PACKAGE_FILTER_HEAD) == PACKAGE_FILTER_HEAD) wprintf(L"(HEAD) "); if ((flags & PACKAGE_FILTER_DIRECT) == PACKAGE_FILTER_DIRECT) wprintf(L"(DIRECT) "); if ((flags & PACKAGE_FILTER_RESOURCE) == PACKAGE_FILTER_RESOURCE) wprintf(L"(RESOURCE) "); if ((flags & PACKAGE_FILTER_BUNDLE) == PACKAGE_FILTER_BUNDLE) wprintf(L"(BUNDLE) "); wprintf(L"\n"); wprintf(L" Path : %s\n", packageInfo->path); const PACKAGE_ID * packageId = &(packageInfo->packageId); wprintf(L" Name : %s\n", packageId->name); wprintf(L" Publisher : %s\n", packageId->publisher); 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); }
Requirements
|
Minimum supported client |
Windows 8 [desktop apps only] |
|---|---|
|
Minimum supported server |
Windows Server 2012 [desktop apps only] |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- GetCurrentPackageFamilyName
- GetCurrentPackageFullName
- GetCurrentPackageId
- GetCurrentPackagePath
- GetPackageInfo