-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathAppModel.PackageGraph.h
More file actions
36 lines (30 loc) · 1.07 KB
/
AppModel.PackageGraph.h
File metadata and controls
36 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.
#ifndef __APPMODEL_PACKAGEGRAPH_H
#define __APPMODEL_PACKAGEGRAPH_H
#include <appmodel.h>
namespace AppModel::PackageGraph
{
inline HRESULT GetCurrentPackageGraph(
const UINT32 flags,
std::uint32_t& packageInfoCount,
const PACKAGE_INFO*& packageInfo,
wil::unique_cotaskmem_ptr<BYTE[]>& buffer)
{
packageInfoCount = 0;
packageInfo = nullptr;
std::uint32_t bufferLength{};
LONG rc{ ::GetCurrentPackageInfo(flags, &bufferLength, nullptr, &packageInfoCount) };
if ((rc == APPMODEL_ERROR_NO_PACKAGE) || (packageInfoCount == 0))
{
// No packages. We're done
return S_OK;
}
RETURN_HR_IF(HRESULT_FROM_WIN32(rc), rc != ERROR_INSUFFICIENT_BUFFER);
buffer = wil::make_unique_cotaskmem<BYTE[]>(bufferLength);
RETURN_IF_WIN32_ERROR(::GetCurrentPackageInfo(flags, &bufferLength, buffer.get(), &packageInfoCount));
packageInfo = reinterpret_cast<PACKAGE_INFO*>(buffer.get());
return S_OK;
}
}
#endif // __APPMODEL_PACKAGEGRAPH_H