WinRT is a COM library but it is not necessary to initialize COM, and you do not work with COM pointers directly.
You also do not need to handle HRESULT
return codes, as C++/WinRT converts these errors to exceptions such as winrt::hresult-error
.
The cppwinrt.exe
tool in the Windows SDK generates the WinRT headers that provide the C++17 projections of the WinRT data types.
The winrt
namespace contains the C++17 projections of the WinRT data types.
The WinRT headers are generated using the fully qualified namespaces.
For example the projections for the types defined in the Windows.Foundation.Collections
namespace are generated into the winrt/Windows.Foundation.Collections.h
header file.
WinRT contains many namespaces, so it is useful to add using namespace
statements in your source files.
using namespace winrt;
using namespace Windows::Foundation;
In Visual Studio 2019, you can create a WinRT project from the New Project window.
Select the Windows Console Application (C++/WinRT) project template.
To support WinRT, a C++ project needs:
The entry point of a WinRT program is the main
function like a standard C++ program.