'What is the necessary lifetime for SetWindowTextA string parameter

I have a program that creates a std::string s on the heap and passes it to the SetWindowTextA(hWnd, s.c_str()) My question is how long does that string need to live? Does SetWindowTitleA copy the string or do I need to keep the string alive?



Solution 1:[1]

Since my question was answered in the comments here is the the quick answer to anyone having the same question:

Yes SetWindowTitleA will create a copy of the passed in const* char. So the necessary lifetime is until the function returns. Then the passed string can be deleted, dropped or whatever.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RedCrafter LP