Skip to content

cppwinrt.h: Improve conversion of error information #495

Open
@arthuraraujo-msft

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions