Author
Topic: C++ - Saving / Loading data (Read 3560 times)

Hi, first of all - I want someone to do exactly as I want and not to make any external ideas up or ask why i want it like so etc...

So, sorry bout that - to the topic:

I want a simple C++ example (with includings and stuff - a fully working program) which asks user a number and saves it TO THE EXE, TO A INI-FILE or TO A TXT FILE - or all 3.But inorder to test this data-reading, I want it so - that when the program starts, it prints a list where user can read the saved numbers and after press of an enter, it will ask new number, saves that and again on startup it creates the list an so on...

I don`t need encryption, or security - I`ll do it later if I want, just give me example of that.

I would mostly want example of saving to exe and txt-file, ini is not so important.Remember to test it, lol - so i dont have to reply with bugreport.

What kind of "ask user number" functionality do you want? Since you only say "C++" I'd guess a console mode app, but it doesn't hurt specifying more explicitly.

A little note: saving to .exe won't work - there's been various tricks proposed during the years, but most of them have relied on undocumented stuff and don't work today. If you really want to save to exe, you have to take the route I've done with fSekrit: basically, copy current .exe to a temporary location, append data there, launch temporary .exe with special flag to make it overwrite original exe, launch now-overwritten-with-new-data original exe with flag to make it delete the temporary copy.

I think just a simple "cin>>" for number-input is fine - as Im using that "Command-Propt-Like-Thingy". Btw, I tried to create that "Virtual-Screen" (where you can create ie. pictures by adding colored pixels in it) by using some tutorial but it had something to do with Pascal and It doesn`T workd on Win7, 64bit - So is there any other way, pascal-tut was all about some weird assemblycode :|?

And let`s change the exe to the .dll then, that would be nice - no matter how sucky it is.

The code isn´t a big thing to do, but I don´t understand how to save it to an .exe or .dll file? I see no sense in doing this or at least a way to do this without destroying the exe-file. Is this prog for educational use?

It`s just because I presonally think it`s the most easiest thing to do o_O.

Let`s say that I wan`t to make a standalone prog with the ask number and list em on startup -functions, and I cannot use registry(blocked from the prog).And I want this program so standalone, that it is only the .exe - nothing else.

But like I said, I would even respect the example of doing it with .txt but dll and exe would be nice too!

P.S Speaking of is it for educational use... It is, but how do I make a program which uses different processes without any reason except that it won`t let user to close it cause of that?

You can write to the data hunks in dlls or exes, but its not so easy to do. You have to take care of the file structure, offsets and pointers. It could be a problem to the program task to write at its own file while running - I think the OS will not allow this (try to delete an .exe while running it in the background).Viruskillers or other security software will treat these changes as an illegal operation and attack.Reading and writing to normal text-files is incomparable to the others and much more easier to do.You seem to need a console application. The listing of the complete content after each new number is for bigger amounts not very nice to look at.It´s also a little bit strange how to implement a "virtual screen with colors" in a command prompt? Did you try to write to the vga-buffer directly (ASM)?

Outputs via DOS-interrupts is nowadays outdated and not working any more if you don´t use a VGA-Emulator like DosBox.Here and here are some examples (at the bottom).Additional ones are these: Here and here.All you need is there inside. You only have to mix the file-output and text-input together - so you still have a little thing to do.