SHGetFolderPath Deprecated: What is alternative to retrieve path for Windows folders?
The alternative is described in the documentation to which you link. Namely it is SHGetKnownFolderPath
.
However, SHGetKnownFolderPath
is only available on Vista or later. So if you use load time linking, and run a program that calls SHGetKnownFolderPath
on XP, then that program will fail to start. This is clearly a problem if you wish to support XP.
Now, you could switch to run time linking of SHGetKnownFolderPath
. Carry out a version check before you call it, and if the function is not available, then fall back to SHGetFolderPath
.
Personally, I would not let this deprecation worry you excessively. Microsoft are renowned for maintaining backwards compatibility. Don't expect SHGetFolderPath
to disappear any time soon. You will find that SHGetFolderPath
exists in Windows 8 and I would expect it still to be present in whatever Windows is current 10 years from now. My advice is to stick to load time linking, and only switch to SHGetKnownFolderPath
when you give up supporting XP.
Your other question, that you ask in an edit, is how to call SHGetFolderPath
. You need to respect the requirements which are laid out at the bottom of the MSDN documentation topic which you linked to in your question. Specifically, include Shlobj.h
and pass Shlobj.lib
to the linker.
It is linked right at the top, SHGetKnownFolderPath.
CSIDL_COMMON_APPDATA is replaced by FOLDERID_ProgramData in the new API.