Does your code even compile? data() returns a const string. That isn't compatible with the LPWSTR
that the function requires. When I try your test code the compiler fails the call as I would expect.
std::wstring GetRecycleBinPath()
{
std::wstring path;
path.resize(MAX_PATH);
SHGetSpecialFolderPathW(NULL, &path[0], CSIDL_BITBUCKET, FALSE);
//SHGetSpecialFolderPathW(NULL, path.data(), CSIDL_BITBUCKET, FALSE);
std::clog << ::GetLastError() << std::endl;
return path;
}
As for the underlying issue, you cannot get the recycling bin using this function. It isn't a real folder and therefore there is no path to return. This applies to any virtual folder actually.
Since the folder is virtual there is really nothing you can do with the path itself. Can you clarify what you're planning to do with the folder as there is likely an API to handle that (e.g. restore or clear the bin).