Hello @Shyam Butani ,
Yes, it is valid to put the pointer into a winrt::hstring via “take ownership from abi” and then allowing the winrt::hstring to destruct.
You can use detach_abi to avoid bumping the reference count:
int main()
{
hstring str = L"hello world";
void* ptr = detach_abi(str);
hstring str2(ptr, take_ownership_from_abi);
assert(str == L"");
assert(str2 == L"hello world");
}
Another valid way is to call WindowsDeleteString((HSTRING)ptr), which is the OS’s ABI method for managing the lifetime ABI HSTRINGs.
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.