12

C++/WinRT nasty gotcha: winrt::param::hstring constructed from std::wstring_view...

 3 years ago
source link: https://devblogs.microsoft.com/oldnewthing/20210823-00/?p=105598
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

C++/WinRT nasty gotcha: winrt::param::hstring constructed from std::wstring_view requires null termination

Raymond

August 23rd, 2021

The std::string_view (and wide buddy std::wstring_view) represent a contiguous sequence of characters, not necessarily null-terminated.

One nasty gotcha in C++/WinRT is that if you try to construct a winrt::hstring from a std::wstring_view, the C++/WinRT library requires that your std::wstring_view be followed with a null terminator. If the character one past the end of the view is not a null character, then the C++/WinRT library terminates the program.

I’m not sure if std::wstring_view was the correct data type for representing “a range of characters, followed by a null terminator”, but it’s what C++/WinRT chose, and we’re stuck with it. But at least now you know the bonus null terminator requirement.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK