I need this to move a file to recycle bin by using SHFileOperation function and SHFILEOPSTRUCT structure.
Is this way safe ? ( I’m starting from wide char string object.)
wstring wstr = L"my test"
wstr += L'\0'
wchar_t* = wstr.c_str();
and since I’ve added zero in string object and conversion to c-string added another it should be valid PCZZWSTR… but… if there is some ‘clever’ code along the way sensing that the zero is already at the end ?
Yes, what you showed will work. You are adding an explicit null character to the end of the wstring’s data, and then
c_str()will return a pointer that is terminated by a second null terminator, thus satisfying theSHFileOperation()requirement.