You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Moogly

Beginner

  • "Moogly" is male
  • "Moogly" started this thread

Posts: 17

Date of registration: Mar 9th 2009

  • Send private message

1

Tuesday, March 10th 2009, 1:32am

Reading an INI File?

Pardon if this may have been posted already but I use the following code in a VB6 project of mine :


Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#If Win16 Then
 Declare Function WritePrivateProfileString Lib "Kernel" (ByVal AppName As String, ByVal keyname As String, ByVal NewString As String, ByVal FileName As String) As Integer
 Declare Function GetPrivateProfileString Lib "Kernel" Alias "GetPrivateProfilestring" (ByVal AppName As String, ByVal keyname As Any, ByVal default As String, ByVal ReturnedString As String, ByVal MAXSIZE As Integer, ByVal FileName As String) As Integer
 Declare Function ShellExecute Lib "shell.dll" (ByVal hwnd As Integer, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Integer
#Else
 Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
 Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long
 Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#End If

Function ReadINI(ByVal section, keyname, FileNaam, Optional standard As String) As String
Dim str As String
str = String(100000, Chr(0))
ReadINI = Left(str, GetPrivateProfileString(section, ByVal keyname, standard, str, Len(str), FileNaam))
End Function

Function WriteINI(ByVal sSection As String, ByVal sKeyName As String, ByVal sNewString As String, ByVal sFileNaam As String) As Integer
WritePrivateProfileString sSection, sKeyName, sNewString, sFileNaam
End Function


But it errors on Jabaco, what I basically need is a way to read and write files, if anyone can help via something that replaces this code also if you could show me how to use the function on this it would be something like :

socket(0).LocalPort = Val(ReadINI("server", "port", SettingIni))

or basically

ReadINI("server", "port", SettingIni)

Where the ini file would look like this :

[SERVER]
port=234

basically I need this for a project I'm working on where I need to read mysql settings off an ini file for convenience to the end user (they might not have Jabaco especially if they're on Linux etc...) anyways any help would be greatly appreciated and credited in my project!

maXim

Trainee

  • "maXim" is male

Posts: 53

Date of registration: Jan 5th 2009

Location: Sesto Fiorentino, Florence (ITALY)

Occupation: design & development (HW, SW & FW)

Hobbies: chess, fly fishing, good wine and beautiful women!

  • Send private message

2

Tuesday, March 10th 2009, 11:00am

Hi Moogly,

why continue with the Windows API? ini4j is a good wrapper to manage INI files in Windows format and javaini also seems to be another good solution... ;)

Best Regards,

Massimo

This post has been edited 2 times, last edit by "maXim" (Mar 10th 2009, 11:59am)


Posts: 14

Date of registration: Feb 16th 2009

  • Send private message

3

Tuesday, March 10th 2009, 11:36pm

Hi Moogly,

why continue with the Windows API? ini4j is a good wrapper to manage INI files in Windows format and javaini also seems to be another good solution... ;)

Best Regards,

Massimo


Yes why not but... tomorrow another API questions will be asked, and the actual API support that Jabaco handles is JNI, quite good but not supporting BYREF parameters nor capable of handling callbacks, BUT JNA supports it!


See https://jna.dev.java.net/ and you'll be very surprized, and I really encourage Manuel to natively support JNA instead of JNI and then everyone will be able to manage any kind of Apicalls BYREF params, Structures, Callbacks and so on...



Hope Manuel will read this :)

Manuel

Administrator

  • "Manuel" is male

Posts: 256

Date of registration: Jul 16th 2008

Location: Erlangen, Germany

Occupation: Software Developer

Hobbies: Jabaco, game theory, text-mining

  • Send private message

4

Tuesday, March 10th 2009, 11:53pm

Quoted

Hope Manuel will read this :)
I noticed your good suggestion. We should improve the API-support. JNA is a possible way - I'm not sure with the LGPL license and the size of JNA...

Posts: 14

Date of registration: Feb 16th 2009

  • Send private message

5

Wednesday, March 11th 2009, 12:05am

Quoted

Hope Manuel will read this :)
I noticed your good suggestion. We should improve the API-support. JNA is a possible way - I'm not sure with the LGPL license and the size of JNA...


I'm not an expert at LGPL :)


But the good point of JNA is its numerous supports : Win32, 64, Unix, Linux, MacOS... + its capabilities.

IMO it should be a very good source of inspiration! :P

Moogly

Beginner

  • "Moogly" is male
  • "Moogly" started this thread

Posts: 17

Date of registration: Mar 9th 2009

  • Send private message

6

Wednesday, March 11th 2009, 9:39am

My target audience all use Windows, but I do want it to be multi-platform for convenience, I don't care what method is used to read the INI long as it works :P

Rate this thread
WoltLab Burning Board