getenv() vs SHGetFolderPath()

what's the difference between
 
getenv("APPDATA"); 


and

SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath);
which one should I prefer? Thanks
Last edited on
getenv() is a cross-platform function. Or to tell it correctly, there are some cross platform compilers which support that function. SHGetFolderPath is Win32 only. It depends on where you want to compile and your compiler, I estimate on Windows because you put it here. I'd prefer the first one, it seems a bit easier and shorter ;-)
You should use neither and use https://msdn.microsoft.com/en-us/library/bb762188.aspx instead.

APPDATA is a platform specific path anyways. It doesn't matter if you use a platform specific method of obtaining it. Just make sure you do it in the most reliable way. Frankly, I tend to stay away from the mimic POSIX functions in the WinAPI when possible as they don't tend to conform to the POSIX standard (nor do they claim to either). For instance, using getenv can result in weird issues in a unicode-enabled application where you should use _wgetenv instead, despite the explicit documentation saying the runtime maintains both. `SHGetKnownFolderPath` is a much more clear functionality and works regardless.
Topic archived. No new replies allowed.