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
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 it with AppName being "SHAPES" and KeyName being NULL you will get :-
"Red Green Blue "
if you called GetPrivateProfileString with the AppName as NULL then the returned buffer would contain "SHAPES
Square=10 Round=5 Oval=89 Red=1 Green=43 Blue=78
Hello umbongo, thanks again for your answer :-) -----------8<------------ If you called it with AppName being "SHAPES" and KeyName being NULL you will get :- "Red
Green Blue "
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 !
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
CodeMonkey, I'm not quite sure I understand your question, but here goes... Here's an example piece of code
.data 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 .code start: invoke GetPrivateProfileString,NULL,addr szKeyName,addr szDefault,addr szResult,255,addr szIniFile
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 :-
Square=1 Circle=2 Red=1 Blue=2 Green=3
which will display the names of the string it found... Hope this helps. umbongo
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