-
Notifications
You must be signed in to change notification settings - Fork 233
/
Unpackaged.cpp
71 lines (58 loc) · 2.38 KB
/
Unpackaged.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright(c) Microsoft Corporation.
// Licensed under the MIT License.
//
// DynamicDependenciesBasic.cpp :
// This file shows the headers and usings required to call apis in the Windows App SDK.
// To run with auto-initialization of the Windows App Runtime, run as-is
// To explicitly control initialization:
// - edit project file and remove WindowsPackageType=None
// - uncomment the code below with WINAPPSDK-INITIALIZE: tags
//
#include <iostream>
#include <windows.h>
#include <MddBootstrap.h>
#include <wil/result.h>
// Include the header to demo usage of a Windows App SDK API
#include "winrt\Microsoft.Windows.System.Power.h"
#include "Unpackaged.h"
namespace winrt
{
using namespace winrt::Microsoft::Windows::System::Power;
}
int main()
{
// WINAPPSDK-INITIALIZE: uncomment code below to have explicit control of initialization
//THROW_IF_FAILED(ExplicitlyInitializeWinAppRuntime());
// Call a simple Windows App SDK API, and output the result
auto dispStatus = winrt::PowerManager::DisplayStatus();
std::cout << "Hello World!\n";
std::cout << "Power.DisplayStatus is " << (int)dispStatus << "\n";
// WINAPPSDK-INITIALIZE: uncomment code below to control initialization
//ExplicitlyCleanUpWinAppRuntime();
}
// Method to handle any explicit initialization of Windows App Runtime
// Not needed if using WindowsPackageType=None in project properties
HRESULT ExplicitlyInitializeWinAppRuntime()
{
// Constants for dynamic dependencies lookup.
// Preview tag not needed for GA release, eg: versionTag{ L"" };
const UINT32 majorMinorVersion{ 0x00010000 };
PCWSTR versionTag{ L"" };
// Initialize values for the call to the Dynamic Dependencies bootstrapper
const PACKAGE_VERSION minVersion{};
const HRESULT hr{ MddBootstrapInitialize(majorMinorVersion, versionTag, minVersion) };
// Check the return code for errors. If there is an error, display the result.
if (FAILED(hr))
{
wprintf(L"Error 0x%X in MddBootstrapInitialize(0x%08X, %s, %hu.%hu.%hu.%hu)\n",
hr, majorMinorVersion, versionTag, minVersion.Major, minVersion.Minor, minVersion.Build, minVersion.Revision);
return hr;
}
return S_OK;
}
// Method to handle any clean up required for explicity initialization of Windows App Runtime
void ExplicitlyCleanUpWinAppRuntime()
{
// Release the DDLM and clean up.
MddBootstrapShutdown();
}