Hello to all !
Maybe someone has a solution for this Problem.
I need to read all keys and values of a specified INI-Section. So I try to use the API-function "GetPrivateProfileSection".
This is the declaration:
Declare GetPrivateProfileSection as "GetPrivateProfileSectionA" of "kernel32.dll"
lpAppName As String
lpReturnedString As String
nSize As Long
lpFileName As String
result as long
End Declare
Later in the code I use this function:
Dim szBuf as String
GetPrivateProfileSection.lpAppName = "MainMenu"
GetPrivateProfileSection.lpReturnedString = szBuf
GetPrivateProfileSection.nSize = 255
GetPrivateProfileSection.lpFileName = "C:Test.ini"
GetPrivateProfileSection.Execute
The variable szbuf is needed in the function for the returned string after reading the section.
In VB it is declared as: Dim szBuf as String * 255
How this can be done in FNXBasic?
Will the returned string will be in the variable szBuf?
Thank you for your answers.
Gerhard
Read INI-Section with API-function
-
- Posts: 10
- Joined: Tue Sep 17, 2013 10:55 am
Read INI-Section with API-function
Now I found a solution for the above Problem:
Dim sFile as String
Dim szBuf as String
sFile = "C:Test.ini"
szBuf = Space$(10240)
GetPrivateProfileSection.lpAppName = "MainMenu"
GetPrivateProfileSection.lpReturnedString = szBuf
GetPrivateProfileSection.nSize = Len(szBuf)
GetPrivateProfileSection.lpFileName = sFile
GetPrivateProfileSection.Execute
Print Trim$(szBuf)
The variable szBuf needs to be initialized.
In the above example I did it with space of 10 KB of size.
This indicates that the returned string can be in that size.
This should normally be enough for one INI-section.
The next step is to split this string in keys and values.
Gerhard
Dim sFile as String
Dim szBuf as String
sFile = "C:Test.ini"
szBuf = Space$(10240)
GetPrivateProfileSection.lpAppName = "MainMenu"
GetPrivateProfileSection.lpReturnedString = szBuf
GetPrivateProfileSection.nSize = Len(szBuf)
GetPrivateProfileSection.lpFileName = sFile
GetPrivateProfileSection.Execute
Print Trim$(szBuf)
The variable szBuf needs to be initialized.
In the above example I did it with space of 10 KB of size.
This indicates that the returned string can be in that size.
This should normally be enough for one INI-section.
The next step is to split this string in keys and values.
Gerhard
Read INI-Section with API-function
Good, thanks.? ?:)
Read INI-Section with API-function
Thanks for sharing.
Read INI-Section with API-function
I don`t know if you can use it but an ini file is just a text file so you can read it with the filestream component.
Here`s the code to test.
best regards
dim f as filestream,c as integer
f.open("fnxbasic.ini")
for c=1 to f.linecount
print f.readline
next c
showmessage "wait"
Here`s the code to test.
best regards
dim f as filestream,c as integer
f.open("fnxbasic.ini")
for c=1 to f.linecount
print f.readline
next c
showmessage "wait"