Reputation: 93
I recently started playing with C++/WinRT (https://marketplace.visualstudio.com/items?itemName=CppWinRTTeam.cppwinrt101804264).
My goal is to create an app that downloads a file and saves it to the downloads folder. I decided to use BackgroundDownloader class (https://learn.microsoft.com/en-us/uwp/api/windows.networking.backgroundtransfer.backgrounddownloader?view=winrt-19041).
However, when I try to create BackgroundDownloader
instance my program crashes with the following exception:
Exception thrown at 0x76729AB2 in MyApp.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x004FEEF4.
int main()
{
// The line bellow causes the crash:
winrt::Windows::Networking::BackgroundTransfer::BackgroundDownloader backgroundDownloader;
}
What did I wrong?
Upvotes: 0
Views: 669
Reputation: 459
WinRT is a bunch of COM interfaces so you need to initialize the subsystem first. You must initialize the WinRT apartment first like this
winrt::init_apartment();
or
winrt::init_apartment(apartment_type::single_threaded);
for UI applications
Upvotes: -2