In my C++/WinAPI application I get the My Documents folder path using this code:
wchar_t path[MAX_PATH];
SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,SHGFP_TYPE_CURRENT,path);
One of the users runs my program on a pc connected to his corporate network. He has the My Documents folder on a network. So my code returns something like
\\paq\user.name$\My Documents
Though he says he has a local copy of My Documents.
The problem is that when he ‘swaps VPN’, the online My Documents becomes unavailable and my program crashes with the system error code 64 “The specified network name is no longer available” ( it tries to write to the file opened in the online my docs folder).
How can I always get the local My Documents folder path using C++/WinAPI?
CSIDL_PERSONALis 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, andCSIDL_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.