Save INI files with ease.

Posts 1–5 of 5 · Page 1 of 1
Save INI files with ease.
Hey, here is a fixed INI lib code for your projects. Save INI files with ease + Unicode support unlike everything else you can find. Since there was nothing like this I release it here for you.

For your WinAPI module
pastebin DOT com/a4gr1W8g"]
Class code or in a helper module
pastebin DOT com/Y8zqcG6M
If this is too complex for you, I recommend to learn the basics and to read the parameters. Have fun with this! :blackhat:
Another way;

Code:
Module modINI
    Private Declare Unicode Function WritePrivateProfileString Lib "kernel32" _
    Alias "WritePrivateProfileStringW" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As String, ByVal lpString As String, _
    ByVal lpFileName As String) As Int32

    Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" _
    Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As String, ByVal lpDefault As String, _
    ByVal lpReturnedString As String, ByVal nSize As Int32, _
    ByVal lpFileName As String) As Int32

    Public Sub writeIni(ByVal iniFileName As String, ByVal Section As String, ByVal ParamName As String, ByVal ParamVal As String)
        Dim Result As Integer = WritePrivateProfileString(Section, ParamName, ParamVal, iniFileName)
    End Sub

    Public Function ReadIni(ByVal IniFileName As String, ByVal Section As String, ByVal ParamName As String, ByVal ParamDefault As String) As String
        Dim ParamVal As String = Space$(1024)
        Dim LenParamVal As Long = GetPrivateProfileString(Section, ParamName, ParamDefault, ParamVal, Len(ParamVal), IniFileName)
        ReadIni = Left$(ParamVal, LenParamVal)
    End Function
End Module

Usage:

Code:
Imports System****

Public Class Form1

    Dim File = Application.StartupPath + "\Test.ini"
    Dim Section = "Settings"
    Dim Author = "Author"
    Dim org = "Organization"

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = ReadIni(File, Section, Author, "")
        TextBox2.Text = ReadIni(File, Section, org, "")
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        writeIni(File, Section, Author, TextBox3.Text)
        writeIni(File, Section, org, TextBox4.Text)
    End Sub
End Class
Source: tech.reboot.pro
Quote Originally Posted by Mrtm4n View Post
Another way;
How is this another way? Looks like the same to me..

Who still uses INI files anyways?
I once used a library which did not support characters like ÖÄÜ, so I checked pinvoke which did not have a solution either. That is why I went on the WindowsAPI and changed this in order to work.

I personally use INI files in most projects. Simple yet effective solution for settings or language files. And this is very beginner friendly unlike XML readers or similar solutions.
Microsoft said INI files are superannuated nowadays, you should use something like XML. They are as cushy/readable as INI files are, other than being the current "vogue" for initialization files.
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?