Add a hook to throw_hresult for integration with WIL #843
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#841
Why is this change being made?
This change is being made to improve the interop between cppwinrt and WIL (particularly WIL's logging abilities for errors). It introduces a hook to the
winrt::throw_hresultmethod that <wil/cppwinrt.h> will be able to fill in with a valid function pointer. That function pointer will allow WIL's logging abilities to gain knowledge of the exceptions that are originated within cppwinrt.Briefly summarize what changed
An extern function pointer was created which is empty by default. If it is set then
winrt::throw_hresultwill call it before continuing with actually throwing the exception.One interesting note is that several of the parameters to
winrt_throw_hresult_handlerare not actually filled in. There is an expectation that C++20 source_location will allow correct file/function/line annotation to these calls for optimum debuggability. That hopefully isn't too far off in the future so the contract is being established now to avoid the need to change it soon in a backwards-compatible way. Once source_location does come online there will be no changes needed on the WIL side to log them properly.How was the change tested?
build_test_all.cmdwas used for this. A new test case was added to confirm that throw_hresult does call the handler if set. I also copied my private build of cppwinrt.exe to a test project to confirm that the generated base.h matches expectations.