YEP you basically have it.
Here is another simple sample that I used when trying another game engine.
I used a data structure to store the setup info into.
The data structure:
struct ProgramSettings
{
int iWindowedMode;
int iDesktopWidth;
int iDesktopHeight;
int iGameWidth;
int iGameHeight;
int iGameColor;
int iGameZBuffer;
int iUseMusic;//If true then music will be used
int iMusicVolume; //100% is full volume
//int iMusicPlaying;//If true then music is looping and producing sound
char szMusicFile [128];//The file name stored in this variable will be used for the music
char szLastPlayerIP [128];
char szLastPlayerPort [128];
char szLastServerIP [128];
char szLastServerPort [128];
};
The usage:
pProgram = new ProgramSettings;
//Get current desktop size.
pProgram->iDesktopWidth = GetSystemMetrics(SM_CXSCREEN);
pProgram->iDesktopHeight = GetSystemMetrics(SM_CYSCREEN);
//Check for saved program settings (BUT NOT GAME SETTINGS).
char szTempBuffer [128];
pProgram->iGameWidth = GetPrivateProfileInt("ProgramSetup","GameWidth",800,".\\Redidit.set");
pProgram->iGameHeight = GetPrivateProfileInt("ProgramSetup","GameHeight",600,".\\Redidit.set");
pProgram->iWindowedMode = GetPrivateProfileInt("ProgramSetup","WindowedMode",0,".\\Redidit.set");
pProgram->iUseMusic = GetPrivateProfileInt("ProgramSetup","UseMusic",1,".\\Redidit.set");
pProgram->iMusicVolume = GetPrivateProfileInt("ProgramSetup","MusicVolume",50,".\\Redidit.set");//Preset to 50% volume
GetPrivateProfileString("ProgramSetup","MusicFile","..\\sound\\eveofwar.mid",pProgram->szMusicFile,128,".\\Redidit.set");
GetPrivateProfileString("NetworkSetup","LastPlayerIP","127.0.0.1",pProgram->szLastPlayerIP,128,".\\Redidit.set");
GetPrivateProfileString("NetworkSetup","LastPlayerPort","6790",pProgram->szLastPlayerPort,128,".\\Redidit.set");
GetPrivateProfileString("NetworkSetup","LastServerIP","127.0.0.1",pProgram->szLastServerIP,128,".\\Redidit.set");
GetPrivateProfileString("NetworkSetup","LastServerPort","6790",pProgram->szLastServerPort,128,".\\Redidit.set");
WritePrivateProfileString("ProgramSetup","GameWidth", _itoa(pProgram->iGameWidth, szTempBuffer, 10),".\\Redidit.set");//update info in case file does not exist
WritePrivateProfileString("ProgramSetup","GameHeight", _itoa(pProgram->iGameHeight, szTempBuffer,10),".\\Redidit.set");
WritePrivateProfileString("ProgramSetup","WindowedMode", _itoa(pProgram->iWindowedMode, szTempBuffer,10),".\\Redidit.set");//Window=1, FullScreen=0
WritePrivateProfileString("ProgramSetup","UseMusic", _itoa(pProgram->iUseMusic, szTempBuffer,10),".\\Redidit.set");//Music=1, NoMusic=0
WritePrivateProfileString("ProgramSetup","MusicVolume", _itoa(pProgram->iMusicVolume, szTempBuffer,10),".\\Redidit.set");
WritePrivateProfileString("ProgramSetup","MusicFile", pProgram->szMusicFile,".\\Redidit.set");
WritePrivateProfileString("NetworkSetup","LastPlayerIP", pProgram->szLastPlayerIP,".\\Redidit.set");
WritePrivateProfileString("NetworkSetup","LastPlayerPort", pProgram->szLastPlayerPort,".\\Redidit.set");
WritePrivateProfileString("NetworkSetup","LastServerIP", pProgram->szLastServerIP,".\\Redidit.set");
WritePrivateProfileString("NetworkSetup","LastServerPort", pProgram->szLastServerPort,".\\Redidit.set");
The result
[ProgramSetup]
GameWidth=800
GameHeight=600
WindowedMode=0
UseMusic=1
MusicVolume=50
MusicFile=..\sound\eveofwar.mid
[NetworkSetup]
LastPlayerIP=127.0.0.1
LastPlayerPort=6790
LastServerIP=127.0.0.1
LastServerPort=6790
Notice how one normally does the reads first.
If there is data read then we use it or the default data if data is not being read.
Then we follow with writing the data back into the INI file so that it gets recreated no matter if the data is there or not there.
Normally in the game if the INI file becomes corrupted, it is just a matter of erasing the corrupt INI file and automatically a new default valued INI file will automatically get recreated.
EDIT: for google search just search for the functions
EG:
GetPrivateProfileStringA()
etc