The SHGetFolderPath()
function is deprecated beginning with Windows Vista: http://msdn.microsoft.com/en-us/library/bb762181%28v=VS.85%29.aspx
What is the alternative way to retrieve the path to the Application Folder in Windows?
SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, szPath)
Aside from that, why do I get those errors when using this function:
Error 1 error C2065: 'CSIDL_COMMON_APPDATA' : undeclared identifier
Error 2 error C3861: 'SHGetFolderPath': identifier not found
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 callsSHGetKnownFolderPath
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 toSHGetFolderPath
.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 thatSHGetFolderPath
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 toSHGetKnownFolderPath
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, includeShlobj.h
and passShlobj.lib
to the linker.