🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

file manip question->

Started by
3 comments, last by farmersckn 24 years, 5 months ago
ok, i''ve been poking around with a bunch of *.ini files and the like and i''ve noticed that some of them have lines like this: UserName="BigBob" GraphMode=13... etc... it looks like a variable is being assigned a value from within the file. how is this accomplished? i mean, is there something in the program that reads the file that says if (string_in_file == UserName) then read from the file a string and assign it to UserName? or does it read a null string or something? btw, i''ve also seen comments: //this file must be x bytes long, don''t delete the next x lines of x''s.... ???? anyone got answers? tnx in advance.
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
Advertisement
INI files are sort of like the Windows Registry, except older. They just hold data in a nice text format that a program can read and write to. It''s not necessarily assigning a variable from within the file (although, in DOS, you could assign environment variables from batch files, but that''s another story...), but all it is doing is assigning a "key" that the program can read. For example, in Win.ini you might have something like:
ScrollBarWidth = 16
which would tell Windows that the desired scroll bar width is 16 pixels. Or, for a better example, you could have a program that is dialog based, and every time you start it, you want the dialog to be in the same place on the screen. You could make an ini file for your program, and put in it something like:
MainDialogX = 100
MainDialogY = 100
And then read that in in the beginning of your program, and do something like:
x = ReadKey(MainDialogX);
y = ReadKey(MainDialogY);
MainDialog.SetPos(x,y);

Of course, those aren''t the real function names or anything, but I''m just trying to show that the definitions in ini files aren''t really variables, it''s just data for the program to read in.
As far as comments go, all that happens is when the program reads the file, it skips to the next line when it finds a comment, but it''s not really related to programming or anything, even if it uses the same syntax as C++




------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
The only place I''ve seen the "this file must be x bytes long" message is when trying to enforce MS-DOS compatibility in system files. Just trust them on those.

The functions to access the ini files are GetProfileString, GetPrivateProfileString, GetPrivateProfileInt, etc.

And surprise surprise to set the values use SetProfileString, etc.

Of course this is all deprecated and shouldn''t be done in any Win32 program. Proper 32 bit programs should use the registry.
Yep, do like Microsoft, store stuff in the registry... Visual Studio stores bloody 6 Megs in the registry... Jeez.

/Niels
<b>/NJ</b>
There are also some "fun" gotchas with the *PrivateProfile* apis. For instance, writing something with WritePrivateProfileString isn''t enough to actually get it into the ini file immediately. This is because the data is actually buffered in the registry. If you want to see the data in the file, you''ll have to flush the data, by:

WritePrivateProfileString (null, null, null, );

Also, Win9x only buffers up to 64k data in an ini file. Any ini file longer than that is simply truncated when you try to read from it. (WinNt doesn''t have this problem...)

As was said above. Just use the registry, its much nicer and is the preferred method.

Notwen
Notwenwww.xbox.com

This topic is closed to new replies.

Advertisement