Dave's Brain

Browse - 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).

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.