There’s a lot of missing gaps in the winrt/c++ content out there, so here’s a solved problem that I had. This is mainly so I can find it again…

#include <winrt/Windows.Web.h>
#include <winrt/Windows.Web.Http.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Storage.Streams.h>

auto http_client = Windows::Web::Http::HttpClient();
auto uri = Windows::Foundation::Uri(L"https://<FILE URL>"); 
auto buffer = co_await http_client.GetBufferAsync(uri);
auto reader = DataReader::FromBuffer(buffer);
auto header_version = reader.ReadUInt64();

You can also download the file, using the following code. In this example it downloads it into a subfolder of the applications storage, which is hidden away under AppData\Local\Packages\ but you could save it to Downloads by changing the LocalFolder() call.

#include <winrt/Windows.Web.h>
#include <winrt/Windows.Web.Http.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Storage.Streams.h>

auto http_client = Windows::Web::Http::HttpClient();
auto uri = Windows::Foundation::Uri(L"https://<FILE URL>");
auto buffer = co_await http_client.GetBufferAsync(uri);
auto reader = DataReader::FromBuffer(buffer);

auto data = buffer.data();
uint32_t len = buffer.Length();
winrt::array_view<uint8_t> view(data, data + len);

winrt::Windows::Storage::StorageFolder folder = winrt::Windows::Storage::ApplicationData::Current().LocalFolder();
auto outfolder = co_await folder.CreateFolderAsync(L"Folder Name", winrt::Windows::Storage::CreationCollisionOption::OpenIfExists);
auto outfile = co_await outfolder.CreateFileAsync(L"File Name", winrt::Windows::Storage::CreationCollisionOption::ReplaceExisting);
co_await winrt::Windows::Storage::FileIO::WriteBytesAsync(outfile, view);

The code here feels a bit wrong with the array_view on the data. There’s a byte array here that’s being handled directly and that’s a code smell that I need to look at getting rid of. If there isn’t already a helper function then it’s a good candidate for creating one.