블로그 이미지
안녕1999

카테고리

전체 (3067)
자바스크립트 (20)
안드로이드 (14)
WebGL (4)
변비 (17)
정치,경제 (35)
C언어,ARM (162)
컴퓨터(PC, Note Book, 윈.. (41)
전자회로, PCB (27)
유머,안웃긴,GIF,동영상 (118)
국부론60 (71)
모듈(PCB) (3)
건강 (2)
FreeCAD (25)
PADS (43)
퇴직,퇴사,구직,취업 활동 (3)
C# (86)
엑셀 (8)
워드 (0)
LabView (6)
레고 (30)
FPGA (0)
Total
Today
Yesterday

달력

« » 2024.12
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

공지사항

최근에 올라온 글

Ini File class

C# / 2020. 10. 10. 23:45
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Reflection;
using System.IO.Ports;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;
public class IniFile
{
	static String m_ini_file;
	String m_Section;
	static StringBuilder temp;
	const int buf_size = 1024 * 4;
	public IniFile()
	{
		if (temp == null)
		{
			m_ini_file = System.Reflection.Assembly.GetExecutingAssembly().Location;
			m_ini_file=m_ini_file.Replace(".exe", ".ini");
			temp = new StringBuilder(buf_size);
		}
		else
		{ }

		m_Section = "Data";
	}

	[DllImport("kernel32.dll")]
	private static extern int GetPrivateProfileString(
		String section, String key, String def, StringBuilder retVal, int Size, String filePat);

	[DllImport("Kernel32.dll")]
	private static extern long WritePrivateProfileString(
		String Section, String Key, String val, String filePath);

	public string GetIniFileName()
	{
		return m_ini_file;
	}
	public void SetIniFileName(string inifile)
	{
		m_ini_file = inifile;
	}
	public void SetSection(string Section)
	{
		m_Section = Section;
	}
	public void Puts(string Key, string Value)
	{
		string s=Gets(Key, "");
		if (s != Value)
		{
			WritePrivateProfileString(m_Section, Key, Value, m_ini_file);
		}
		else
		{
			//동일함.skip
		}
	}
	public void Put_int(string Key, int Value)
	{
		int a = Get_int(Key, 0);
		if (a != Value)
		{
			WritePrivateProfileString(m_Section, Key, Convert.ToString(Value), m_ini_file);
		}
		else
		{
			//동일함.skip
		}
	}
	public void Put_double(string Key, double Value)
	{
		double a = Get_double(Key, 0.0f);
		if (a != Value)
		{
			WritePrivateProfileString(m_Section, Key, Convert.ToString(Value), m_ini_file);
		}
		else
		{
			//동일함.skip
		}
	}

	public string Gets(string Key, string default_value)
	{
		string s;
		int i = GetPrivateProfileString(m_Section, Key, "", temp, buf_size, m_ini_file);
		if (temp.Length == 0)
		{
			s = default_value;
		}
		else
		{
			s=temp.ToString();
		}
		return s;
	}
	public int Get_int(string Key,int default_value)
	{
		string s=Gets(Key,Convert.ToString(default_value));
		return Convert.ToInt32(s);
	}
	public double Get_double(string Key,double default_value)
	{
		string s = Gets(Key, Convert.ToString(default_value));
		return Convert.ToDouble(s);
	}
}
Posted by 안녕1999
, |

최근에 달린 댓글

글 보관함