Read INI-Section with API-function

In this category you can exchange your programming questions and solutions.
Post Reply
Gerhard P.
Posts: 10
Joined: Tue Sep 17, 2013 10:55 am

Read INI-Section with API-function

Post: # 1120Post Gerhard P.
Sat Sep 28, 2013 10:03 pm

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

Gerhard P.
Posts: 10
Joined: Tue Sep 17, 2013 10:55 am

Read INI-Section with API-function

Post: # 1121Post Gerhard P.
Mon Sep 30, 2013 10:09 pm

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

cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

Read INI-Section with API-function

Post: # 1122Post cvirus
Wed Oct 02, 2013 8:00 am

Good, thanks.? ?:)

Angel
Posts: 87
Joined: Sat Nov 19, 2011 9:34 am

Read INI-Section with API-function

Post: # 1123Post Angel
Wed Oct 02, 2013 11:10 am

Thanks for sharing.

Marco
Site Admin
Posts: 241
Joined: Sat Sep 15, 2018 8:41 pm

Read INI-Section with API-function

Post: # 1124Post Marco
Fri Oct 04, 2013 3:52 pm

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"

Post Reply