工程:在.NET中實(shí)現(xiàn)INI文件讀寫API
版本: 0.2.2
授權(quán)方式:GNU GPL
著作權(quán)所有(c) 2007 Midapex
本程序?yàn)樽杂绍浖荒梢罁?jù)自由軟件基金會(huì)所發(fā)表的GNU通用公共授權(quán)條款規(guī)定,就本程序再為發(fā)布與/或修改;無論您依據(jù)的是本授權(quán)的第二版或(您自行選擇的)任一日后發(fā)行的版本。
本程序是基于使用目的而加以發(fā)布,然而不負(fù)任何擔(dān)保責(zé)任;亦無對適售性或特定目的適用性所為的默示性擔(dān)保。詳情請參照GNU通用公共授權(quán)。
源代碼下載地址:
http://www.shnenglu.com/Files/dyj057/IniFileCliV0.2.2.zip描述:
使用C++/CLI封裝C++實(shí)現(xiàn)的INI文件讀寫API,可以應(yīng)用在.NET平臺(tái)。
已測試通過的開發(fā)環(huán)境:
WinXP+VS2005
應(yīng)用舉例(C#):
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using Midapex;
5
6 namespace TestIniFile
7 {
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 NIniFile ini = new NIniFile("myconfig.ini");
13 string nameKey = "name";
14 string ageKey = "age";
15
16 ini.Section = "student";
17 ini.Write(nameKey, "Tony");
18 ini.Write(ageKey, 20);
19 Console.WriteLine("[{0}]", ini.Section);
20 Console.WriteLine("{0}={1}",nameKey, ini.Read(nameKey, ""));
21 Console.WriteLine("{0}={1}",ageKey, ini.Read(ageKey, -1));
22 }
23 }
24 }
類頭文件聲明如下(C++/CLI):
1 // ***************************************************************
2 // version: 0.2.2 date: 12/13/2007
3 // -------------------------------------------------------------
4 // Wrapper C++ IniFile class for .NET
5 // -------------------------------------------------------------
6 // Copyright (C) 2007 - All Rights Reserved
7 // ***************************************************************
8 //
9 // ***************************************************************
10 #pragma once
11 using namespace System;
12
13 namespace Midapex
14 {
15 public ref class NIniFile
16 {
17 public :
18 NIniFile(String^ fileName)
19 {
20 m_fileName = fileName;
21 }
22
23 property String^ Section
24 {
25 String^ get() { return m_section; }
26 void set (String^ section) { m_section = section; }
27 }
28
29 void Write(String^ key, String^ strVlaue);
30 void Write(String^ key, int intValue);
31
32 String^ Read(String^ key, String^ defaultStrValue);
33 int Read(String^ key, int defaultIntValue);
34
35 private:
36 String^ m_fileName;
37 String^ m_section;
38 };
39 }
posted on 2007-12-13 12:17
天下無雙 閱讀(2211)
評(píng)論(2) 編輯 收藏 引用 所屬分類:
C/C++