hey, could anybody help me with writing and reading of .ini files ? My problem is that i wanna use an .ini file to save 3 lines in it, one is a normal directory name, one is a number, and the 3rd line is just a word again. But i don't know how to write to a certain line in a file, i was writing to files before with CreateFile and WriteFile, but i couldn't get it done that when you write something new in that file that it replaces the first line You guys have any ideas,tutors or code snippets about my problem ? And maybe somebody could tell me how to use .ini files in masm Thanks Typhoon
Posted on 2001-04-11 19:17:00 by Typhoon
I'm sorry that I don't have a code snippet for you. I've never used these api's in asm either....but maybe this'll be enough to get you started. Look up WritePrivateProfileXXX and GetPrivateProfileXXX in your api helps. --4oh4
Posted on 2001-04-11 20:06:00 by 4oh4
This is from my Alarm & countdown Timer program (on Iczelion's site). Everything in the file except the name of the current .wav file is fixed length, so it's fairly easy to position the filepointer to read or write where you want to. The steps are first invoke CreateFile, ADDR iniFileName, GENERIC_READ or GENERIC_WRITE, \ 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL ;try to create a new ini file mov iniHandle, eax invoke GetLastError ;error will show if file exists .IF( eax != ERROR_ALREADY_EXISTS ) ;File Needs to be Created or ; error opening file .IF( eax == 0 ) ;New File Created ;Do what ever needs to be done when the .ini file is created ;My program creates the .ini program the first time the ; program is run unless another file exists with that ; name which does not have my signature invoke CloseHandle, iniHandle ret .ELSE ;Error opening file invoke CloseHandle, iniHandle invoke MessageBox, hWnd, ADDR iniFileName, ADDR AppName, MB_OK ;display error opening file dialog ret .ENDIF .ENDIF ;We're here if the file was successfully opened ;I check this first few characters to make sure this is really ; my .ini file and not another one with the same name invoke ReadFile, iniHandle, ADDR d_buffer, sizeof IDStr, ADDR bRead, NULL ;read IDStr into d_buffer lea edi, d_buffer ;String read from .ini file in d_buffer lea esi, IDStr ;Compare with the one built into this program mov ecx, sizeof IDStr ;How many character to compare cld repe cmpsb ;Compare .IF( !ZERO? ) ;Strings did not compare ret .ENDIF ;after this point you position the FilePointer and either Read or Write invoke SetFilePointer, iniHandle, 10, NULL, FILE_CURRENT ;skips CR, LF, & string "Seconds:" invoke ReadFile, iniHandle, ADDR d_buffer, 2, ADDR bRead, NULL ;reads 2 digit Second string invoke WriteFile, iniHandle, ADDR IDStr, temp_dw, ADDR bRead, NULL ;write IDStr to new file ;When finished, Close and return invoke CloseHandle, iniHandle ret
Posted on 2001-04-11 20:17:00 by farrier
Thanks guys, but about an hour ago i figured out what 4oh4 was suggesting, and it works just fine but i think i'm gonna store my datas in the registry, because that program is for 32bit windows anyways Regards Typhoon
Posted on 2001-04-11 20:40:00 by Typhoon