0

Well that i looking for is, how to create a file to store applicaiton settings, i prefer ini files...

well i found smthing, it work ok, but i cant understand how it work.
What his code do? well this code store informations in *.ini file,
example

[SECTION]
Option1 = Nab
Option2 = Idiot
[SECTION 2]
ImPRO = False
........... // And More...

This my code...

using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace clsINI
{
    public static class config
    {
        public static string path = System.Windows.Forms.Application.StartupPath + @"\Result.ini";
        public static IniFile ini = new IniFile(path);

        public static string getKeyValue(string section, string key)
        {
            string tmp = String.Empty;
            tmp = ini.IniReadValue(section, key);
            return tmp;
        }
    }

    public class IniFile
    {
        public string path;

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
       [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section,
            string key, string def, StringBuilder retVal, int size, string filePath);

        public IniFile(string INIPath)
        {
            path = INIPath;
        }
        public void IniWriteValue(string Section, string Key, string Value)
        {
            WritePrivateProfileString(Section, Key, Value, this.path);
        }

        public string IniReadValue(string Section, string Key)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
            return temp.ToString();

        }
    }
}

How it work lol? i dont see smthink like..

private void WriteToFIle(string section, string key)
{
    StreamWrite sw = new StreamWriter("config.ini");
    sw.AppendText(section, key);
}

well im just new in programming, but the code i found is just an "empety" code, how do that? maby there is a funcion in dll file?

private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

?? i hope you understand me :)

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by pseudorandom21
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.