1

在我的 C++/WinAPI 应用程序中,我使用以下代码获取 My Documents 文件夹路径:

wchar_t path[MAX_PATH];
SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,SHGFP_TYPE_CURRENT,path);

其中一位用户在连接到他公司网络的个人电脑上运行我的程序。他在网络上有我的文档文件夹。所以我的代码返回类似 \\paq\user.name$\My Documents 虽然他说他有我的文档的本地副本。问题是,当他“交换 VPN”时,在线“我的文档”不可用,我的程序崩溃,系统错误代码 64“指定的网络名称不再可用”(它尝试写入在我的在线打开的文件中)文档文件夹)。

如何始终使用 C++/WinAPI 获取本地“我的文档”文件夹路径?

4

1 回答 1

3

CSIDL_PERSONAL is the only official "My Documents" folder. If he redirected that to a network folder, then even Windows would not be able to access "My Documents" when off the VPN. Unlike the various AppData folders (CSIDL_APPDATA, CSIDL_COMMON_APPDATA, and CSIDL_LOCAL_APPDATA), Windows has no concept of separate local and remote "My Documents" folders, so whatever local folder he has would have had to been created manually as a normal folder, and thus the Shell API would not know about it. The only way your app will find it is to ask him where it is.

于 2012-11-03T22:57:34.630 回答