I bulit a program with vars and I want to open the program and to find the vars exucly the same before I close the program


var1 = 1
close program
open program
var1 = 1
Posted on 2004-08-15 11:32:08 by
Use the registry or some external file to store the contents of the variable, and read it back when the program starts.

It sounds like you want to change the contents of the variable in the EXE file - this isn't really possible from a windows program.
Posted on 2004-08-15 11:39:51 by f0dder
You would have to save the variable in a file (for example .ini files) or store it in registry.
Posted on 2004-08-15 11:39:59 by roticv
Write your data to file on exit, and read it back on startup.

Edit: Heh, all replied at the same time.
Posted on 2004-08-15 11:40:35 by iblis
how can I write to .ini , .dat files?
Posted on 2004-08-15 11:42:43 by
Posted on 2004-08-15 11:45:39 by iblis
You can make use of the api WriteProfileString and GetProfileString for .ini files.
Posted on 2004-08-15 11:48:29 by roticv
indeed, file I/O is a not-done for .ini files. anyway are .ini files not very appreciated, better use the registry. it is very easy, you'll need the Reg* api from advapi.dll/lib.
Posted on 2004-08-15 12:42:11 by Mbee
.dat, .ini, whatever. It depends on how easily you want to give users access to initialization data.
I would encourage learning basic file I/O, as it is one of the fundamental concepts with which new programmers should familiarize themselves.

The .ini parsing APIs are dinosaurs from the Win 3.x days, and adhere to a strict format which one may or may not find to their liking or needs. I personally don't like it, but for very simple purposes it works well.

The windows registry is handy, but can quickly become a disaster zone if you don't know what you're doing, and should be used sparingly.
Here are some articles from MS about the registry:

There's also an article which I couldn't immediately find which details the correct steps an application should take when making use of the registry. Try to find it and read it if you can. For the multiuser environments like Windows NT/2k/XP/2k3, there's also the matter of security and permissions, as things might not always behave as expected if you are not running under administrator credentials. This applies to file I/O as well.
Posted on 2004-08-15 14:34:30 by iblis