Hi i know how to read a Section from a Ini File when i know the section name,but how can i show all Sections inside a ini file ? i use a ini as database and the user can make new sections with a random names,this names i like to get . the value for the setting i know. like: (how to get this name) account= username= password= cu
Posted on 2001-07-04 02:47:00 by CodeMonkey
CodeMonkey, First off, I would seriously consider using the registry for this, it would probably be easier... but to answer your question. GetPrivateProfileString allows you to pass NULL as a value for Parameters 1 and 2 (AppName and KeyName) If AppName is NULL then it returns the secion names in a list. If KeyName is NULL then it returns the keys of that section in a list. for example, if you had an ini file with :-


if you called GetPrivateProfileString with the AppName as NULL then the returned buffer would contain "SHAPESCOLOURS" If you called it with AppName being "SHAPES" and KeyName being NULL you will get :- "RedGreenBlue" Easy :) umbongo
Posted on 2001-07-04 05:05:00 by umbongo
Hello umbongo, thanks again for your answer :-) -----------8<------------ If you called it with AppName being "SHAPES" and KeyName being NULL you will get :- "RedGreenBlue" -----------8<------------ cool ! i actual use 4 sections but for every one i have a single command to read the input. now i can safe 3 lines of code by reading them all at once :-) Thanks a lot !
Posted on 2001-07-04 10:16:00 by CodeMonkey
Hi again how should i say it ??? if i try to get a list of all sections inside a ini file,i got only one line. i dont understand those "easy" function "grmbl" since i got only one line ,i try to make a loop with the result that my program hang because he try alltime to get the first section only. ok what i learn now is... GetPrivateProfileString ,here the section like setting1,here the value like test=,here 0,here the buffer....,0,here the path to ini file... in my ini file i use: test=hello1 test=hello2 i then like to get all: for now i use a extra section filled with the other section names and it work fine,but i like to delete my function and use the one you post. can you please help me again ? thanks
Posted on 2001-07-05 03:06:00 by CodeMonkey
CodeMonkey, I'm not quite sure I understand your question, but here goes... Here's an example piece of code

	szAppKey	db	256 dup(0)
	szKeyName	db	256 dup(0)
	szDefault	db	256 dup(0)
	szResult	db	256 dup(0)
	szIniFile	db	"c:\test.ini",0


	invoke GetPrivateProfileString,NULL,addr szKeyName,addr szDefault,addr szResult,255,addr szIniFile

contains :-


then you will get this in szResult:- "SHAPES.COLOURS.." where the '.' means the NULL character so you need a pointer to the string, use the string at the pointer, then move it one byte past the NULL char, if it is pointing at a NULL again, it's the end of the string! like this :-

	lea	eax, szResult

l1:	push	eax
	invoke MessageBox,0, eax,addr szTitle,MB_OK
	pop	eax

l2:	inc	eax				; move along one char
	cmp	byte ptr ,0		; is it a NULL?
	jne	l2				; no, keep looping

	inc	eax				; it was a NULL, move along one more.
	cmp	byte ptr ,0		; is it a NULL again - if so we've finished
	jne	l1				; no, show this messagebox

which will display the names of the string it found... Hope this helps. umbongo
Posted on 2001-07-05 04:29:00 by umbongo