• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Saving data/settings in a program without a separate data file

I have a program built with VC++ 6.0.  I have an array of data, that I would like the user to be able to change, and have it saved for next time the program is run, without having a seperate data file.

How do I do this?

thanks
0
galneweinhaw
Asked:
galneweinhaw
  • 3
1 Solution
 
Jaime OlivaresCommented:
If I understand correctly, you don't want to save data in a separate file but in the same .exe file.
This is not a good practice although it is possible to do with "resources", you can't modify resources in a .exe file that is currently running.
Another alternative is to store in registry, but this is not recommended for large amounts of data, normally this technique is used to store "user preferences".
So you can tell us a little more about the data you want to store.
0
 
galneweinhawAuthor Commented:
Thanks,

Yes, you understand correctly what I'd like to do.

These are settings that would change rarely.  The settings would be  stored, preferably in a single or multiple arrays say 20x5 or something.  I could just do it in a seperate file if it is very difficult.

0
 
Jaime OlivaresCommented:
If data is short I suggest you to store it in Windows registry. Do you have a sample of your data?
Again I don't recommend you to store in the .exe file.

Windows registry is not a separated file, just a big file with all windows (and applications') configuration. Is the proper site to store config information, but not large data as I told you.
I you decide to store in Windows Registry, you can use some helper class to acomplish that.
Have a look to these at codeproject.com:
http://www.codeproject.com/system/simple_registry.asp
http://www.codeproject.com/system/akregistryex.asp
http://www.codeproject.com/system/registryvars.asp
http://www.codeproject.com/system/registry_class.asp

If you are working with arrays, I suggest you to convert you array information in a comma-separated string, before putting it in a registry entry.

Good luck,
Jaime.
0
 
aquila98Commented:
why is it difficult?

a simple .ini file (encypted if you must hide the data) should do:
void ReadOptions()
unsigned long success;
char ret[2048];
DWORD nSize= 2047;
...
memset(ret, 0, nSize);
success= GetPrivateProfileString("SayForInstance:Dimension", "Rows", "0", ret, nSize, m_IniFilePath);
rowcount = atol(ret);
success= GetPrivateProfileString("SayForInstance:Dimension", "Columns", "0", ret, nSize, m_IniFilePath);
colcount = atol(ret);
for (int row= 0; row< rowcount; row++)
{
  for (int col= 0; col< colcount; col++)
  {
      tmp.Format("Cell%d-%d", row,col);
      memset(ret, 0, nSize);
      success= GetPrivateProfileString("Data", tmp, "", ret, nSize, m_IniFilePath);
      if (strlen(ret) > 1)
     {
              put the data in your code somewhere!
             CellsValue[row][col]= ret;
     }
  }
}

and to write the ini:
WritePrivateProfileString("SayForInstance:Dimension", "Columns", "20", m_IniFilePath)
WritePrivateProfileString("SayForInstance:Dimension", "Rows", "5", m_IniFilePath)
for (int row= 0; row< rowcount; row++)
{
  for (int col= 0; col< colcount; col++)
  {
      tmp.Format("Cell%d-%d", row,col);
      WritePrivateProfileString("Data", tmp, CellsValue[row][col], m_IniFilePath)
  }
}

:)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now