我使用下面的函数来尝试并获得文件夹的路径,然后转换该路径的std :: string:HRESULT串(获得的文件路径)C++
std::string getpath() {
TCHAR documents[MAX_PATH];
HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, documents);
std::stringstream pff;
pff << result;
return pff.str();
}
当这个执行,当试图将“\ filename”附加到字符串时,我得到一个“无效的文件名错误”。
请帮忙!
编辑:这是我如何附加到路径:
std::string folder = getpath() + "\\Folder";
我假定双逃逸符号仍然适用。
文档仍然是TCHAR – user3295336 2014-09-02 14:14:28
+1,但某处需要将字符串缓冲区的长度传递给SHGetFolderPath:其中一个参数不应为NULL。 – Bathsheba 2014-09-02 14:17:37
@Bathsheba它应该是MAX_PATH缓冲区,请参阅[SHGetFolderPath](http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181%28v=vs.85%29.aspx)。 – AlexD 2014-09-02 14:19:32