Date: 02-16-2022
Return to Index
created by gbSnippets
If lpAppName is NULL, GetPrivateProfileString copies all
section names in the specified file to the supplied
buffer. If lpKeyName is NULL, the function copies all
key names in the specified section to the supplied
buffer. An application can use this method to enumerate
all of the sections and keys in a file. In either case,
each string is followed by a null character and the final
string is followed by a second null character. If the supplied
destination buffer is too small to hold all the strings, the
last string is truncated and followed by two null characters.
'DWord WINAPI GetPrivateProfileString(
' __in LPCTSTR lpAppName,
' __in LPCTSTR lpKeyName,
' __in LPCTSTR lpDefault,
' __out LPTSTR lpReturnedString,
' __in DWord nSize,
' __in LPCTSTR lpFileName
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg as Dword
Global Sections(), Keys() As String
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local INIFileName As Asciiz * %MAX_PATH, sList, kList As String * 1024
Local Content$, i As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
'use fixed-length string instead of ASCIIZ because the return string includes embedded $NUL bytes
'section names are returned like this: sectionname1 + CHR$(0) + sectionname2 + chr$(0) + sectionname3 + CHR$(0,0)
INIFileName = EXE.Path$ + "test.ini"
GetPrivateProfileSectionNames ByVal VarPtr(sList), ByVal Len(sList), INIFileName
Replace Chr$(0) With " " In sList : sList = trim$(sList)
ReDim Sections(ParseCount(sList," ")-1) As String
Parse sList,Sections(), " " 'splits string a$ at commas (default delimiter)
For i=0 to UBound(Sections)
'Getprivateprofilestring "All", "Left", "300", xResult, %Max_Path, INIFileName
Getprivateprofilestring ByVal Varptr(Sections(i)), "", "", ByVal Varptr(kList), Len(kList), INIFileName
Replace Chr$(0) With " " In kList : kList = trim$(kList)
ReDim Keys(ParseCount(kList," ")-1) As String
Parse kList,Keys()," " 'splits string a$ at commas (default delimiter)
For i = 0 to UBound(Keys)
Content$ = Content$ + $crlf + Sections(i) + " : " + Keys(i)
Next i
Next i
? Content$
End If
End Function
'gbs_00733
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm