Skip to content

Commit b31885e

Browse files
authored
Throw right exception in case of CoCreateInstance failure (#5215)
* Throw right exception in case of CoCreateInstance failure Signed-off-by: godlytalias <[email protected]>
1 parent 0c97f80 commit b31885e

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

dev/WindowsAppRuntime_UniversalBGTaskDLL/Task.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#if __has_include("Task.g.cpp")
77
#include "Task.g.cpp"
88
#endif
9+
#include <wil/result_macros.h>
910

1011
using namespace winrt;
1112
using namespace winrt::Windows::ApplicationModel::Background;
@@ -22,8 +23,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTa
2223
auto lookupobj = values.Lookup(lookupStr);
2324
winrt::guid comClsId = winrt::unbox_value<winrt::guid>(lookupobj);
2425

25-
winrt::Windows::ApplicationModel::Background::IBackgroundTask bgTask = nullptr;
26-
winrt::hresult hr = CoCreateInstance(comClsId, nullptr, CLSCTX_LOCAL_SERVER, IID_IBackgroundTask, reinterpret_cast<void**>(&bgTask));
27-
bgTask.Run(taskInstance);
26+
THROW_IF_FAILED(CoCreateInstance(comClsId, nullptr, CLSCTX_LOCAL_SERVER, IID_IBackgroundTask, reinterpret_cast<void**>(&m_bgTask)));
27+
m_bgTask.Run(taskInstance);
2828
}
2929
}

dev/WindowsAppRuntime_UniversalBGTaskDLL/Task.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace winrt::Microsoft::Windows::ApplicationModel::Background::UniversalBGTa
1212
Task() = default;
1313

1414
void Run(winrt::Windows::ApplicationModel::Background::IBackgroundTaskInstance taskInstance);
15+
private:
16+
winrt::Windows::ApplicationModel::Background::IBackgroundTask m_bgTask = nullptr;
1517
};
1618
}
1719

0 commit comments

Comments
 (0)