Programming Tips - How can I get the common folder for program settings?

Date: 2012aug15 OS: Windows Language: C/C++ Q. How can I get the common folder for program settings? (A place to save settings that apply to all users of my program) A.
BOOL GetAppDataDir(LPSTR szPath, const size_t size) { szPath[0] = '\0'; if (size < MAX_PATH) return FALSE; return SHGetSpecialFolderPathA(NULL, szPath, CSIDL_COMMON_APPDATA, TRUE); }
Make a folder named after your program in there and save your settings files in that folder. In Vista+ that folder might be read-only so use the common docs folder (CSIDL_COMMON_DOCUMENTS) or user-specific app data folder (CSIDL_APPDATA).