Page 1 of 1

Read INI-Section with API-function

Posted: Sat Sep 28, 2013 10:03 pm
by Gerhard P.
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

Posted: Mon Sep 30, 2013 10:09 pm
by Gerhard P.
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

Read INI-Section with API-function

Posted: Wed Oct 02, 2013 8:00 am
by cvirus
Good, thanks.? ?:)

Read INI-Section with API-function

Posted: Wed Oct 02, 2013 11:10 am
by Angel
Thanks for sharing.

Read INI-Section with API-function

Posted: Fri Oct 04, 2013 3:52 pm
by Marco
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"