Needs help - GetPrivateProfileSection?

Just starting out? Need help? Post your questions and find answers here.
vkleonid
User
User
Posts: 15
Joined: Tue May 27, 2003 11:31 am

Needs help - GetPrivateProfileSection?

Post by vkleonid »

Info: The GetPrivateProfileSection function retrieves all the keys and values for the specified section of an initialization (INI) file.
Windows 95/98/Me: The specified profile section must not exceed 32K.
Windows NT/2000 or later: The specified profile section has no size limit.

Help me, please, with using GetPrivateProfileSection in PB?

Code: Select all

BufLen.l=32767
szBuf.s=Space(BufLen)
GetPrivateProfileSection_("Reports", szBuf, BufLen, "sample.ini")
Debug  szBuf
-returns only first key and value :(
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

That's because PB uses null terminated strings and from this quote from the MSDN you'll see that you have to parse the buffer to get all the entries.
MSDN wrote: ... The buffer is filled with one or more null-terminated strings; the last string is followed by a second null character...
So you would have to do something like this, you may have to correct the code some as i haven't tested it yet:

Code: Select all

BufLen.l=32767
*buffer = AllocateMemory(0, BufLen) ; Better use memory buffer instead.
Length.l = GetPrivateProfileSection_("Reports", *buffer, BufLen, "sample.ini")
if Length = BufLen-2
  ; Section didn't fit inside buffer, better allocate more men
  ; and do it again, but i'm not doing that now...
elseif Length
  Repeat
    a$ = Peeks(*buffer)
    if a$ <> ""
      Debug a$
      *buffer+Len(a$)+1
    endif
  Until a$ = ""
Endif
FreeMemory(0)
Something like that should work, as i said - you may have to tweak it yourself some if it doesn't work right away.

Enjoy :)
vkleonid
User
User
Posts: 15
Joined: Tue May 27, 2003 11:31 am

Post by vkleonid »

Big thanks! All work!
Post Reply