You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using WIL with C++/WinRT with the cppwinrt.h header, the winrt_to_hresult_handler global handler is hooked from WIL directly into the C++/WinRT codebase.
The handler allows WIL exceptions to be understood by C++/WinRT and their HRESULTs extracted, but messages are lost in the way when going over the API boundaries because only the HRESULT is converted in winrt::to_hresult().
C++/WinRT makes use of Get and SetErrorInfo() to recover the messages when re-creating the exceptions on the caller side. The set is done inside winrt::hresult_error::to_abi() in winrt::to_hresult() on the server side, but only when winrt_to_hresult_handler is not hooked. The retrieval happens when re-creating the winrt::hresult_error on the caller.
If WIL were to call the to_abi() method in the WIL hook for winrt_to_hresult_handler, it would properly trigger the storage of the message and later on it could be retrieved when C++/WinRT creates a new winrt::hresult_error on the caller side.
The text was updated successfully, but these errors were encountered:
Correct me if I'm wrong, but you seem to effectively be using C++/WinRT as a way to call `RoOriginateError`? There's already a header for that: [result_originate.h](https://github.com/microsoft/wil/blob/master/include/wil/result_originate.h).
Duncan's suggestion resolves this issue. I hadn't seen this before anywhere. Perhaps this could be added to the docs? Especially the C++/WinRT integration docs on the WIL wiki.
When using WIL with C++/WinRT with the
cppwinrt.h
header, thewinrt_to_hresult_handler
global handler is hooked from WIL directly into the C++/WinRT codebase.The handler allows WIL exceptions to be understood by C++/WinRT and their HRESULTs extracted, but messages are lost in the way when going over the API boundaries because only the HRESULT is converted in
winrt::to_hresult()
.C++/WinRT makes use of Get and SetErrorInfo() to recover the messages when re-creating the exceptions on the caller side. The set is done inside
winrt::hresult_error::to_abi()
inwinrt::to_hresult()
on the server side, but only whenwinrt_to_hresult_handler
is not hooked. The retrieval happens when re-creating thewinrt::hresult_error
on the caller.If WIL were to call the
to_abi()
method in the WIL hook forwinrt_to_hresult_handler
, it would properly trigger the storage of the message and later on it could be retrieved when C++/WinRT creates a newwinrt::hresult_error
on the caller side.The text was updated successfully, but these errors were encountered: