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
example:
var1 = 1
close program
open program
var1 = 1
example:
var1 = 1
close program
open program
var1 = 1
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.
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.
You would have to save the variable in a file (for example .ini files) or store it in registry.
Write your data to file on exit, and read it back on startup.
Edit: Heh, all replied at the same time.
Edit: Heh, all replied at the same time.
how can I write to .ini , .dat files?
Some basics on file I/O:
http://spiff.tripnet.se/~iczelion/tut12.html
http://spiff.tripnet.se/~iczelion/tut12.html
You can make use of the api WriteProfileString and GetProfileString for .ini files.
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.
.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:
http://msdn.microsoft.com/msdnmag/issues/1100/Registry/default.aspx
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/registry_storage_space.asp
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.
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:
http://msdn.microsoft.com/msdnmag/issues/1100/Registry/default.aspx
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/registry_storage_space.asp
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.