c++windowsapplication-data

How do I get the application data path in Windows using C++?


I looked all over the internet and there doesn't seem to be a decent solution that I could find. I want to be able to programmatically in C++ obtain the path "%ALLUSERSPROFILE%\Application Data" that explorer can translate into a real path.

Can I do this without relying on third-party code?


Solution

  • Use SHGetFolderPath with CSIDL_COMMON_APPDATA as the CSIDL.

    TCHAR szPath[MAX_PATH];
    if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, szPath)))
    {
        //....
    }