Skip to content

Add make_bstr*(std::wstring_view)#634

Merged
dunhor merged 12 commits into
microsoft:masterfrom
DrusTheAxe:user/drustheaxe/unique_bstr-std_wstring_view
Jul 8, 2026
Merged

Add make_bstr*(std::wstring_view)#634
dunhor merged 12 commits into
microsoft:masterfrom
DrusTheAxe:user/drustheaxe/unique_bstr-std_wstring_view

Conversation

@DrusTheAxe

Copy link
Copy Markdown
Member

WIL only provides only PCWSTR overloads:

  • make_bstr_nothrow(PCWSTR source)
  • make_bstr_failfast(PCWSTR source)
  • inline wil::unique_bstr make_bstr(PCWSTR source);

This PR adds wstring_view overloads calling SysAllocStringLen with the view's data and size directly, correctly handling non-null-terminated string views

  • make_bstr_nothrow(std::wstring_view source)
  • make_bstr_failfast(std::wstring_view source)
  • make_bstr(std::wstring_view source)

This works for non-null-terminated views (substrings, slices), avoids unnecessary and dangerous wcslen walk (we know the wstring_view's length), and is a strict superset of the existing API.

NOTE: A PCWSTR implicitly converts to wstring_view, so these new overloads could replace the existing ones once C++17 is the floor. WIL still supports older standards, so these additional overloads is safer.

Comment thread include/wil/stl.h
Comment thread include/wil/stl.h Outdated
Comment thread include/wil/stl.h Outdated
Comment thread include/wil/stl.h
Comment thread include/wil/stl.h
@DrusTheAxe

Copy link
Copy Markdown
Member Author

/azp run

Comment thread include/wil/resource.h Outdated
Comment thread tests/StlTests.cpp Outdated
Comment thread tests/StlTests.cpp Outdated
Comment thread tests/StlTests.cpp Outdated
Comment thread tests/StlTests.cpp Outdated
DrusTheAxe and others added 7 commits July 6, 2026 18:27
Co-authored-by: Duncan Horn <40036384+dunhor@users.noreply.github.com>
Co-authored-by: Duncan Horn <40036384+dunhor@users.noreply.github.com>
Co-authored-by: Duncan Horn <40036384+dunhor@users.noreply.github.com>
Co-authored-by: Duncan Horn <40036384+dunhor@users.noreply.github.com>
Co-authored-by: Duncan Horn <40036384+dunhor@users.noreply.github.com>
@DrusTheAxe DrusTheAxe requested review from dunhor and jonwis July 7, 2026 05:58
@DrusTheAxe

Copy link
Copy Markdown
Member Author

Incorporated feedback and fixed tests. Need approval of latest commits

@dunhor dunhor merged commit cb3c041 into microsoft:master Jul 8, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants