Originally Posted by
cas
This program is written in almost completely portable C, so it builds fine on Windows, at least with MinGW. However, I'm unfamiliar with how Windows handles user config files, so for the time being the program simply looks in the current directory for a file called progname.ini. I'm sure this is not ideal, so I'm looking for the best place, on Windows, to store a configuration file.
Windows .INI files are, as a tradition, placed in the same folder as the executable and use progname.ini as the filename.
The easiest way to do this is...
Code:
#inlcude <windows.h>
TCHAR SetFile[MAX_PATH + sizeof(TCHAR) ]; // max path length + room for a null.
PTCHAR Ext;
FILE *sf;
// get program's name and path
// note: in console mode you can substitute argv[0]
GetModuleFilename(NULL,SetFile,MAX_PATH);
// locate file extension
Ext = strstr(SetFile,".exe");
// change to INI
strcpy(Ext,".ini");
// load settings file
sf = fopen(SetFile,"r");
// process settings in here.
// save settings
sf = fopen(SetFile,"w");
// process settings out here.
The nice part about doing it this way is that it allows the user to have multiple copies of the program (by renaming) with different settings...
For example: if you have MyProgram.exe it produces MyProgram.ini but if you copy and rename the program to MyFancy.exe it will produce MyFancy.ini automatically.