Page 1 of 1

Needs help - GetPrivateProfileSection?

Posted: Sat Jul 19, 2003 12:09 am
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 :(

Posted: Sat Jul 19, 2003 12:31 am
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 :)

Posted: Sat Jul 19, 2003 12:48 am
by vkleonid
Big thanks! All work!